#include<iostream> #include<string> using namespace std; string s[10] = { "0000","0001","0010","0011","0100","0101","0110","0111","1000","1001" }; string s1[6] = { "1010","1011","1100","1101","1110","1111" }; string DtoB(string x) { string res; int gap = 8 - x.length(); while (gap--) { x.insert(0,"0"); } for (int i = 0;i < 8;i++) { if (x[i] >= '0'&&x[i] <= '9') { res += s[x[i] - '0']; } else { res += s1[x[i] - 'a']; } } return res; } string BtoD(string x) { string res; int a[4]; for (int i = 0;i < 32;i++) { a[i % 4] = x[i] - '0'; if (i % 4 == 3) { int temp = 8 * a[0] + 4 * a[1] + 2 * a[2] + 1 * a[3]; if (temp >= 10) { res += 'a' + temp % 10; } else { res += temp + '0'; } } } return res; } int main() { string r; int x,y; char c; while (getline(cin,r)) { int index1 = r.find(','); int index2 = r.rfind(','); x = stoi(r.substr(index1+1, index2-index1-1)); y = stoi(r.substr(index2+1, r.length() - 1 - index2)); r.erase(index1); string B = DtoB(r); B[31 - x] = '0'; B.replace(B.begin() + 31 - y, B.begin() + 33 - y, "110"); string D = BtoD(B); cout << D << endl; } } /* F:\temp\22494745.28275\Main.cc: In function 'int main()': F:\temp\22494745.28275\Main.cc:52: error: 'stoi' was not declared in this scope */ |
Double click to view unformatted code.