您的位置:首页 > 产品设计 > UI/UE

UVa-424-Integer Inquiry

2014-08-09 17:26 393 查看
AOAPC
I: Beginning Algorithm Contests (Rujia Liu) :: Volume
1. Elementary Problem Solving :: Big
Number



// 424 - Integer Inquiry
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
char s[200];    // at most 100 lines of text
int i, k, n, carry, a[200], t[200];
memset(a, 0, sizeof(a));
while(cin>>s && s[0]!='0')
{
k = 0;
carry = 0;
memset(t, 0, sizeof(t));

for(i=strlen(s)-1; i>=0; i--)
t[k++] = s[i] - '0';

for(i=0; i<200; i++)
{
carry += t[i] + a[i];
a[i] = carry % 10;
carry /= 10;
}
}

n = 200;
while(!a[--n]);
for(i=n; i>=0; i--)
cout << a[i];
cout << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息