It seems like a very easy problem, and it is, but I keep getting WA.
I coded it several times...
Please help me if you see any mistake...
I don't know what could be wrong in such short code.
Thanks!
- Code: Select all
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
string bin( int x )
{
string sol = "";
for( ; x; x /= 2 )
sol.push_back( ( x & 1 ) + '0' );
reverse( sol.begin(), sol.end() );
return sol;
}
int main(){
int t; scanf( "%d", &t );
for( int counter = 1; counter <= t; ++counter ) {
char op; int a, b; scanf( "%X %c %X", &a, &op, &b );
printf( "%013s %c %013s = %d\n", bin(a).c_str(), op, bin(b).c_str(), ( ( op == '+' ) ? a + b : a - b ) );
}
return 0;
}
