The boring Three-God get a boring question. So you have to transform
a binary number to a decimal.
Input
There are muti-case. For each case, there are a binary number, the
binary number’s length is less than 32, and the binary number have no
pre-zero (前导零).
Output
For each binary number, print the decimal numbuer.the decimal number
is less than 2^31 - 1.
Sample Input
1
10
11
Sample Output
1
2
3
注:第一次理解错了,第二次思路错了,QAQ
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char s[34];
while(~scanf("%s",s))
{
int l=strlen(s);
int a[34];
for(int i=0;i<l;i++)
{
a[i]=s[i]-48;
}
int x=a[0];
for(int i=1;i<l;i++)
{
x=x*2+a[i];
}
printf("%d\n",x);
}
return 0;
}