您的位置:首页 > 其它

POJ 1565 Skew Binary pow函数使用

2010-11-30 22:24 323 查看
这题是水题,主要是用到了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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: