View Code of Problem 3307

#include<iostream>
#include<string>
using namespace std;

string s[10] = { "0000","0001","0010","0011","0100","0101","0110","0111","1000","1001" };

string DtoB(string x) {
	string res;
	int gap = 8 - x.length();
	while (gap--) {
		x.insert(0,"0");
	}
	for (int i = 0;i < 8;i++) {
		res += s[x[i] - '0'];
	}
	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() {
	int r,x,y;
	char c;
	while (cin >> r >> c >> x >> c >> y) {
		string B = DtoB(to_string(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\22494678.28208\Main.cc: In function 'int main()':
F:\temp\22494678.28208\Main.cc:43: error: 'to_string' was not declared in this scope
*/

Double click to view unformatted code.


Back to problem 3307