注意边界条件 0
#include<stdio.h> #include<string.h> #define N 440 void print(int t[]) { int i,j,k,high,low; for(low=0;low<2*N;low++) if(t[low]) break; for(high=2*N-1;high>=0;high--) if(t[high]) break; if(N>high) { printf("0."); for(k=N-1;k>=low;k--) printf("%d",t[k]); printf("/n"); } else if(N<=low) { for(k=high;k>=N;k--) printf("%d",t[k]); printf("/n"); } else { for(k=high;k>=low;k--) { if(k==N-1) printf("."); printf("%d",t[k]); } printf("/n"); } } int main() { int i,j,k,len,low,high,a[2*N],b[2*N]; char c[N],d[N]; while(scanf("%s%s",c,d)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); len=strlen(c); for(i=0;i<len;i++) if(c[i]=='.') break; k=0; for(j=i-1;j>=0;j--) { a[N+k]=c[j]-'0'; k++; } k=1; for(j=i+1;j<len;j++) { a[N-k]=c[j]-'0'; k++; } len=strlen(d); for(i=0;i<len;i++) if(d[i]=='.') break; k=0; for(j=i-1;j>=0;j--) { b[N+k]=d[j]-'0'; k++; } k=1; for(j=i+1;j<len;j++) { b[N-k]=d[j]-'0'; k++; } for(j=0;j<2*N;j++) { a[j]+=b[j]; if(a[j]>9) { a[j]-=10; a[j+1]++; } } j=0; for(i=0;i<2*N;i++) j+=a[i]; if(j==0) { printf("0/n"); continue; } print(a); } }
posted on 2010-04-13 13:16 草头菜 阅读(82) 评论(0) 编辑 收藏 举报
Powered by: 博客园 Copyright © 2024 草头菜 Powered by .NET 8.0 on Kubernetes