这题是水题,主要是用到了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; }

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐