Link: http://poj.grids.cn/practice/2973/
Question:
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
In the skew binary representation, the k-bit value xk indicates xk * (2 k + 1-1 ). The possible numbers on each bit are 0 or 1, and the last non-zero bit can be 2, for example, 10120 (skew) = 1 * (25-1) + 0 * (24-1) + 1 * (23-1) + 2 * (22-1) + 0 * (21-1) = 31 + 0 + 7 + 6 + 0 = 44. the top 10 skew numbers are 0, 1, 2, 10, 11, 12, 20, 100, 101, and 102.
-
Input
-
The input contains one or more rows. Each row contains an integer n. If n = 0, the input ends. Otherwise, n is a skew.
-
Output
-
For each input, it is output in decimal format. After being converted to decimal, n cannot exceed 231-1 = 2147483647
-
Sample Input
-
1012020000000000000000000000000000010100000000000000000000000000000011100111110000011100001011011020000
-
Sample output
-
44214748364632147483647471041110737
Code:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> MAX = (scanf(,chs) != EOF && strcmp(chs, sum = step = ( i = strlen(chs)-; i >= ; i-- sum += (chs[i] - ) * (step - step *= cout<<sum<< }
Ideas:
1. Use int to save the result.
2. You must use a string to read data.
3. Use step for Optimization