标签:strlen size 练习 ace string mes col microsoft turn
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <algorithm> using namespace std; int main() { char chr1[1010],chr2[1010]; int t; int len1,len2,len; cin>>t; for(int s=1;s<=t;s++){ if(s!=1) cout<<endl; int i,j=0,k=0; scanf("%s %s",chr1,chr2); int a[1010]={0},b[1010]={0},c[1010]={0}; len1=strlen(chr1); len2=strlen(chr2); for(i=len1-1,j=0;i>=0;i--) a[j++]=chr1[i]-‘0‘; for(i=len2-1,k=0;i>=0;i--) b[k++]=chr2[i]-‘0‘; if(len1>len2) len=len1; else len=len2; int m=0; for(i=0;i<len;i++) { int temp=a[i]+b[i]+m; c[i]=temp%10; m=temp/10; } if(a[i-1]+b[i-1]>=10) c[i]=1; else { c[i]=0; i--; } printf("Case %d:\n",s); printf("%s + %s = ",chr1,chr2); for(;i>=0;i--) cout<<c[i]; cout<<endl; } return 0; }
标签:strlen size 练习 ace string mes col microsoft turn
原文地址:https://www.cnblogs.com/jianqiao123/p/12075781.html