2016-08-10
UVA - 575 Skew Binary
题目大意:根据题目给出的特殊进制转化。
解题思路:第 K 位上的数乘以(2 ^ k - 1),所有相加。
注意:数字太大,需要以字符串形式进行输入。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
char str[100000000];
int main() {
while ( scanf("%s", str) ) {
if ( strcmp( str, "0") == 0 )
break;
int sum = 0;
int len = strlen(str);
for (int i = len-1; i >= 0; i--)
sum += (pow(2,(len - i)) - 1) * (str[i]-'0');
cout << sum << endl;
}
return 0;
}