您的位置:首页 > 其它

zoj 1712 Skew Binary

2012-03-21 12:04 337 查看
#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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: