现在的位置: 首页 > 综合 > 正文

zoj 1712 Skew Binary

2012年05月28日 ⁄ 综合 ⁄ 共 415字 ⁄ 字号 评论关闭
#include "iostream"
#include "stdio.h"
#include "string.h"
using namespace std;

int main()
{
	char input[50];
	int num[50], len, i, ans, temp, tag;
	while (scanf("%s", input))
	{
		memset(num, 0, sizeof(num));
		ans = 0, temp = 2, tag = 1;
		if (strcmp(input, "0") == 0) break;
		len = strlen(input);
		for (i = 0; i < len; i++)
			num[len-i-1] = input[i] - 48;
		for (i = 0; i < len; i++)
		{
			ans += num[i] * (temp - 1);
			temp *= 2;
			if (ans > 2147483647)
			{
				cout << 2147483647 << endl;
				tag = 0;
				break;
			}
		}
		if (tag)
			cout << ans << endl;
	}
}

【上篇】
【下篇】

抱歉!评论已关闭.