这题是水题,主要是用到了C++字符串和cmath中的pow函数。 最近课程有点多,做POJ时间不够,还是要抓紧一些,尤其是动态规划、搜索题等要多练。 #include <iostream> #include <string> #include <cmath> using namespace std; int main(){ string s; while(1){ cin>>s; if (s == "0") break; long result = 0; int k = 1; string::iterator it; for (it = s.end()-1;it!=s.begin();it--) { result += (*it - '0')*(pow(double(2),k++) - 1); } result += (*it - '0')*(pow(double(2),k) - 1); cout<<result<<endl; } return 0; }