//其实看到有多组测试,题目却又没说输入某个数字时退出时,从这就能知道用字符串存储了 #include "stdio.h" #include "string" #include "math.h" using namespace std; int main(){ char buf[1000];string str; while (fgets(buf,1000,stdin)!=NULL) { str = buf;int sum = 0; str.pop_back(); for (int i = 0; i<str.size(); ++i) { sum += (buf[i]-'0')*(pow(2,str.size()-i)-1); buf[i] = '\0'; } printf("%d\n",sum); str.clear(); } }