欸,刷水题上瘾了,这样不好,不好。
这个代码G++能通过而c++不能,有点奇怪,改天研究下,先挖个坑。
#include<iostream>
using namespace std;
#include<string.h>
#include<cmath>
int main()
{
int num,len;
char str[33];
cin>>str;
while(1)
{
num=0;
if(str[0]=='0'&&strlen(str)==1)break;
len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]=='0')continue;
else
{
num+=(str[i]-'0')*(pow(2,len-i)-1);
}
}
cout<<num<<endl;
cin>>str;
}
return 0;
}