| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
代码写的非常的水,求大牛帮忙优化~~~#include <iostream>
#include <stdio.h>
#include <cstring>
#include <map>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
int i,t=0,len;
char a[1000];
while(scanf("%s",a)!=EOF)
{
char b[1000]={'0'};
while(strcmp(a,"0")!=0)
{
reverse(a,a+strlen(a));
len=strlen(a);
for(i=0;i<len;i++)
{ if(i==(strlen(b)))
{
b[i]='0';
}
t=(b[i]-'0')+(a[i]-'0')+t;
b[i]=t%10+'0';
t=t/10;
if(t&&i==(strlen(b)-1)) b[i+1]='0';
}
while(t)
{
t=(b[i]-'0')+t;
b[i]=t%10+'0';
t=t/10;
if(t&&i==(strlen(b)-1))
{
b[i+1]='0';
}
i++;
}
scanf("%s",a);
}
reverse(b,b+strlen(b)); printf("%s\n",b);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator