hdu1002 大数相加问题

这个题对于 几个月前的我简直是噩梦  好在磕磕绊绊终于写出来了

由于自己的问题  还被巨巨嘲讽了

         

 1 1.#include<stdio.h>
 2  2.#include<string.h>
 3  3.int main()
 4  4.{
 5  5.char a[10001], b[10001],c[10001];
 6  6.int len1,len2;
 7  7.int i,j=1,n,p,k;
 8  8.while(scanf("%d",&n)!=EOF&&n>=1&&n<=20)
 9  9.{
10  10.  scanf("%s %s",a,b);   printf("Case %d:\n",j);  
11  11. printf("%s + %s = ",a,b);  
12  12. len1=strlen(a)-1;  
13  13. len2=strlen(b)-1;  
14  14. p=0;  
15  15. for(i=0;len1>=0||len2>=0;i++,len1--,len2--)     
16  16.{             
17  17.if(len1>=0&&len2>=0)
18  18.{c[i]=a[len1]+b[len2]-'0'+p;}             
19  19.if(len1>=0&&len2<0)
20  20.{c[i]=a[len1]+p;}             
21  21.if(len1<0&&len2>=0)
22  22.{ c[i]=b[len2]+p;}  
23  23.p=0;             
24  24.if(c[i]>'9')
25  25.{c[i]=c[i]-10; p=1;}     
26  26.}  
27  27.if(p==1)
28  28.{
29  29.printf("%d",p);
30  30.}  
31  31.while(i--)
32  32.{printf("%c",c[i]);}  
33  33.j++;            
34  34.}                
35  35.return 0;           
36  36.}
戳这里

 

恩 就是一道见到到家的高精度 但是 所谓举一而反三 明白了这个  还是对自己有帮助的!

 

posted @ 2014-12-22 00:04  SenberHu  阅读(154)  评论(0编辑  收藏  举报