| 
 | 
 
 
发表于 2022-10-6 13:05:56
|
显示全部楼层
 
 
 
- #include <bits/stdc++.h>
 
 - using namespace std;
 
  
- int l, la, lb;
 
 - string f, s;
 
 - char op;
 
  
- short a[1001], b[1001], ans[1002];
 
  
- void read(string va, string vb){
 
 -     memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(ans, 0, sizeof(ans));
 
 -     la = va.size(); lb = vb.size(); l = la > lb ? la : lb;
 
 -     for(int i = la - 1; i >= 0; i--) a[la-i-1] = va[i] - '0';
 
 -     for(int i = lb - 1; i >= 0; i--) b[lb-i-1] = vb[i] - '0';
 
 - }
 
  
- void print(short x[]){
 
 -     for(int i = l-1; i >= 0; i--) cout << x[i];
 
 -     cout << endl;
 
 - }
 
  
- void add(short x[], short y[]){
 
 -     int c = 0;
 
 -     for(int i = 0; i < l; i++){
 
 -         ans[i] = x[i] + y[i] + c;
 
 -         c = ans[i] / 10;
 
 -         ans[i] %= 10;
 
 -     }
 
 -     if(c){ans[l] = c; l++;}
 
 - }
 
  
- int main(){
 
 -     ios::sync_with_stdio(0);
 
  
-     cin >> f >> s;
 
 -     read(f, s);
 
 -     add(a, b);
 
 -     print(ans);
 
 -     return 0;
 
 - }
 
  复制代码 |   
 
评分
- 
查看全部评分
 
 
 
 
 
 |