提交时间:2023-10-06 18:05:49
运行 ID: 105464
#include<iostream> #include<string> #include<cmath> using namespace std; int a[1005],b[1005]; int main(){ string x,y; cin>>x>>y; int xs = x.size(); int ys = y.size(); for (int i = xs - 1;i >= 0;i--){ a[i] = x[xs - i - 1] - 48; } for (int i = ys - 1;i >= 0;i--){ b[i] = y[ys - i - 1] - 48; } int maxl = max(xs,ys); int o = 0; for (int i = 0;i < maxl;i++){ a[i] += b[i]; if (a[i] >= 10){ a[i + 1]++; a[i] %= 10; o = 1; } else{ o = 0; } } if (o == 1){ maxl++; } for (int i = maxl - 1;i >= 0;i--){ cout<<a[i]; } return 0; }