标签:
Description
Input
Output
Sample Input
Sample Output
#include<iostream> #include<stdio.h> #include<cmath> #include<string.h> using namespace std; int f(char a[],char b[],int s[]) { int m=strlen(a),n=strlen(b),i,x[1005],y[1005],k; memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); k=max(m,n); if(m==k){ for(i=0;i<m;i++)x[i]=a[i]-‘0‘; for(i=m-1;i>=m-n;i--)y[i]=b[n-m+i]-‘0‘; } if(n==k){ for(i=0;i<n;i++)y[i]=b[i]-‘0‘; for(i=n-1;i>=n-m;i--)x[i]=a[m-n+i]-‘0‘; } s[0]=0; for(i=1;i<k+1;i++)s[i]=x[i-1]+y[i-1]; for(i=k;i>=0;i--){ if(s[i]>9){ s[i]-=10; s[i-1]++; } } return k; } int main() { char a[1005],b[1005]; int n,k=1; cin>>n; while(k<=n){ cin>>a>>b; cout<<"Case "<<k<<":"<<endl; cout<<a<<" + "<<b<<" = "; int s[1005]; int t=f(a,b,s); for(int i=0;i<t+1;i++){ if(s[0]==0&&i==0)continue; cout<<s[i]; } if(k!=n)cout<<endl; cout<<endl; k++; } //system("pause"); return 0; }
格式错误好几次
标签:
原文地址:http://www.cnblogs.com/farewell-farewell/p/5185368.html