菜菜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

题意:

按照这个公式模拟

10120skew = 1×(25 1)+0×(24 1)+1×(23 1)+2×(22 1)+0×(21 1) = 31+0+7+6+0 = 44.

#include<iostream>
#include <stdio.h>
#include <memory.h>
#include<queue>
#include<math.h>
using namespace std;

int main()
{
	freopen("d:\\1.txt", "r", stdin);
	string str;
	while (cin >> str)
	{
		int length = str.length();
		if(length == 1 && str[0] == '0')
			return 0;
		int total = 0;
		for(int i = length - 1; i >= 0; i--)
		{
			total += (str.at(i) - '0') * (pow(2, length - i) - 1);
		}
		cout<<total<<endl;
	}
	return 0;
}

  

posted on 2017-05-14 16:40  好吧,就是菜菜  阅读(213)  评论(0编辑  收藏  举报