Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=960
Steps : Example
1) Read the number N to encrypt M = 265
2) Interpret N as a decimal number X1= 265 (decimal)
3) Convert the decimal interpretation of N to its binary representation X1= 100001001 (binary)
4) Let b1 be equal to the number of 1’s in this binary representation B1= 3
5) Interpret N as a Hexadecimal number X2 = 265 (hexadecimal)
6) Convert the hexadecimal interpretation of N to its binary representation X2 = 1001100101
7) Let b2 be equal to the number of 1’s in the last binary representation B2 = 5
8) The encryption is the result of M xor (b1*b2) M xor (3*5) = 262
This student failed Computational Organization, that’s why this student asked the judges of ITESM Campus Monterrey internal ACM programming Contest to ask for the numbers of 1’s bits of this two representations so that he can continue playing.
Task :
You have to write a program that read a Number and give as output the number b1 and b2
5 5
完整代码:
/*0.016s*/ #include<cstdio> inline int bitnum(int num) { int count = 0; while (num) { if (num & 1) ++count; num >>= 1; } return count; } int main() { int t, m, b1, b2; scanf("%d", &t); while (t--) { scanf("%d", &m); b1 = bitnum(m), b2 = 0; while (m) { b2 += bitnum(m % 10); m /= 10; } printf("%d %d\n", b1, b2); } return 0; }