YangFan's Number
YangFan is a wayward boy who likes to count in his own way.
The number he writes may be 0 or 1 for each digit, and the last non-zero digit may be 2, and the value of the k-th digit xk denotes .
For example:
Input
The input contains one or more lines, each line contains an integer n. If n = 0 means the input is over, otherwise n is a number written by YangFan.
Output
For each number written by YangFan, output its decimal representation. After conversion to decimal, n < 2^31.
这个题很郁闷,一开始看题看错了,以为输入的直接是十进制,然后写了个高精加,发现还是wa,就继续身体发现并不是10进制,用字符数组储存后进行单位运算直接a
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i,j,k;
char a[100000],temp;long long sum;
temp=getchar();
while(temp!='0')
{i=0;
sum=0;
memset(a,0,sizeof(a));
while(temp!='\n')
{
a[i++]=temp;
temp=getchar();
}
for(i-=1,j=1;i>=0;--i,++j)
{
sum+=(a[i]-'0')*(pow(2,j)-1);
}
cout<<sum<<endl;
temp=getchar();
}
return 0;
}