//DEV C++ 5.11
//20年前偽科班,為教孩子學OJ,算是初學者一枚,望大神指點
//只求AC,不求最優:(
# include <iostream>
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
using namespace std;
int main() {
int t,t1;
int m,n;
char a1[21][1001],b1[21][1001];
cin >>t;
for (t1=0; t1<t; t1++) {
cin >>a1[t1] >>b1[t1];
}
for (t1=0; t1<t; t1++) {
char a[1001],b[1001];
int c[1001]= {0},d[1001]= {0},e[1001]= {0};
int i=0,p,q,k,j=0;
p=strlen(a1[t1]);
q=strlen(b1[t1]);
for(i=0; i<p; i++) {
c[i]=a1[t1][p-i-1]-'0';
}
for(i=0; i<q; i++) {
d[i]=b1[t1][q-i-1]-'0';
}
for(i=0; i<1001; i++) {
e[i]=(c[i]+d[i]+j) % 10 ;
j=(c[i]+d[i]+j) / 10;
if (c[i]==0 && d[i]==0) {
k=i+1;
break;
}
}
if(t1>0) {
cout<<endl<<endl;
}
cout << "Case "<<t1+1 <<":"<<endl;
cout << a1[t1] << " + "<< b1[t1]<<" = ";
for (i=0; i<k; i++) {
if (i==0 && e[k-i-1]==0) {
continue;
}
cout<<e[k-i-1];
}
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/104799.html
標籤:C++ 語言
上一篇:關于虛擬地址和物理地址的問題
下一篇:leetcode-977
