| ||||||||||
| 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 | |||||||||
Re:poj1503测试数据过了,O 开头的也考虑了,为什么还是不过呢???帮忙看看吧In Reply To:poj1503测试数据过了,O 开头的也考虑了,为什么还是不过呢???帮忙看看吧 Posted by:Justlikeanddoit at 2009-02-10 00:43:01 > #include<iostream>
> #include<cstring>
> using namespace std;
> void Add(char s1[], char s2[], char result[200])
> {
> char Ans[200];
> char a[101],b[101];
> int i,Len,Len1,Len2,k;
> for (i=0;i<=100;i++)
>
> {
>
> a[i]=0;
>
> b[i]=0;
>
> Ans[i]=0;
>
> }
> for(i=101;i<200;i++)
> Ans[i]=0;
>
> Len1=strlen(s1);
>
> Len2=strlen(s2);
>
> if (Len1>Len2) Len=Len1;
>
> else Len=Len2;
>
>
> k=0;
>
> for (i=Len1-1;i>=0;i--) a[++k]=s1[i]-'0';
>
> k=0;
>
> for (i=Len2-1;i>=0;i--) b[++k]=s2[i]-'0';
>
> for (i=1;i<=Len;i++)
>
> {
>
> a[i]=a[i]+b[i];
>
> if (a[i]>=10)
>
> {
>
> a[i]=a[i]-10;
>
> a[i+1]++;
>
> }
>
> }
>
> while(!a[Len+1])
> {
> Len--;
> }
>
> k=0;
>
> for (i=Len+1;i>=1;i--) Ans[k++]=a[i]+'0';
> strcpy(result, Ans);
> }
> int main()
> {
> char str[100];
> char sum[200];
> memset(sum,0,sizeof(sum));
> while(scanf("%s",&str))
> {
> if(str[0]=='0'&&str[1]=='\0') break;
>
> Add(sum,str,sum);}
> cout<<sum<<endl;
> return 0;
>
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator