玩原神玩的
2023-08-19 11:41:46
发布于:广东
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main(){
string s1,s2;
int a,b,nums[105],count=-1,len1,len2,len3,tmp;
cin >> s1 >> s2;
len1 = s1.size();
len2 = s2.size();
if(len1>len2){
for(int i = 0 ;i<len1-len2;i++){
s2 = "0"+s2;
}
len2 = len1;
}
else if(len2>len1){
for(int i = 0 ;i<len2-len1;i++){
s1 = "0"+s1;
}
len1 = len2;
}
// cout << s2 <<endl;
len3 = max(len1,len2);
for (int i = 0 ; i<101;i++){
nums[i] = 0;
}
for (int i = 0;i<len3;i++){
a = s1[len1-i-1]-'0';
b = s2[len2-i-1]-'0';
count ++;
if (a<0|| a >9) a=0;
else if (b<0 || b>9) b=0;
// cout <<s1[a] << ' ' << s2[b] << endl;
// cout << a << ' '<<b<<endl;
nums[i] += a+b;
if (nums[i]>9){
// cout << nums[i]<<endl;
nums[i+1] = 1;
nums[i] %=10;
}
// cout << nums[i]<<endl;
}
// cout << count;
if (nums[len3+1])count++;
if (nums[count]==0)count++;
for (int j = count;j>-1;j--){
cout << nums[j];
}
return 0;
}
这里空空如也
有帮助,赞一个