-
在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1)。
每个位上的可能数字是0 或 1,最后面一个非零位可以是2,
例如, 10120(skew) = 1*(25-1) + 0*(24-1) + 1*(23-1) + 2*(22-1) + 0*(21-1) = 31 + 0 + 7 + 6 + 0 = 44.
前十个skew数是 0、1、2、10、11、12、20、100、101、以及102。 -
输入包含一行或多行,每行包含一个整数n。如果 n = 0 表示输入结束,否则n是一个skew数
-
可能有多组测试数据,对于每一个输入,
输出它的十进制表示。转换成十进制后, n 不超过 231-1 = 2147483647 -
10120 200000000000000000000000000000 10 1000000000000000000000000000000 11 100 11111000001110000101101102000 0
-
44 2147483646 3 2147483647 4 7 1041110737
-
题目描述:
-
输入:
-
输出:
-
样例输入:
-
样例输出:
题目比较简单,要注意pow()的使用
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
char array[1000];
int i;
while (scanf("%s", array)) {
if (array[0] == '0' && strlen(array) == 1)
break;
int result = 0, temp;
int len = strlen(array);
for (i = 0; i < len; i++) {
temp = pow(2, len-i);
result += (array[i] - '0') * (temp - 1);
}
printf("%d\n", result);
}
return 0;
}