HDU1047
WA3次。。
一看就晓得是高精+,也明白是输出格式要注意,就是忘了和0的情况一直纠结纠、结纠结到蛋疼...
#include <stdio.h> #include <string.h> #define maxn 200 char s[maxn]; int a[maxn],sum[maxn]; int main () { int n,i,j,k; scanf ("%d",&n); for (k = 0;k<n;++k) { memset (sum,0,sizeof (sum)); while (~scanf ("%s",s)) { if (!strcmp(s,"0"))break; int jin = 0,len = strlen (s); memset (a,0,sizeof (a)); for (i = 0;i<len;++i) a[i] = s[len-i-1]-'0'; for (i = 0;i<maxn;++i) { int t = a[i]+sum[i]+jin; sum[i] = t%10; jin = t/10; } } for (i = maxn-1;i>=0;i--)if (sum[i])break; if (i<0)printf ("0"); else for (j = i;j>=0;--j) printf ("%d",sum[j]); printf ("\n"); if (k!=n-1)printf ("\n"); } return 0; }
弱者究竟为何而战?!