题解
2024-07-30 17:35:45
发布于:广东
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
void Readsum(string a,string b){
string c="";
int k = min(a.size(),b.size());
int l = max(a.size(),b.size())-k;
int flag = 0;
for (int i=0;i<k;i++){
char d = a[k-1-i]-'0'+b[k-1-i]-'0'+flag;
if (d > '9'){
d -= 10;
flag = 1;
}char e = d+48;
c = e+c;
if (d <= '9'){
flag = 0;
}
}printf("%s",c.c_str());
}
int main(){
string a,b;
cin >> a >> b;
string A=a,B=b;
if (A.size() > B.size()){
for (int i=0;B.size() < A.size();i++){
B = "0"+B;
}
}if (A.size() < B.size()){
for (int i=0;B.size() > A.size();i++){
A = "0"+A;
}
}
Readsum(A,B);
return 0;
}
这里空空如也
有帮助,赞一个