#include <bits/stdc++.h>
using namespace std;
int main(){
string first, second; cin>>first>>second;
vector<int> result(5001, 0);
if(first.length()>second.length()) swap(first, second);
//-------------------------------
int i = 1;
while(i<=first.length()){
result[i-1] += int(first[first.length()-i] - '0') + int(second[second.length()-i] - '0');
i++;
result[i-1] = result[i-2]/10;
result[i-2]%=10;
}
while(i<=second.length()){
result[i-1] += int(second[second.length()-i] - '0');
i++;
result[i-1] = result[i-2]/10;
result[i-2]%=10;
}
if(result[i-1]!=0) cout<<result[i-1];
for(int j=i-2; j>=0; j--) cout<<result[j];
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <bits/stdc++.h> using namespace std; int main(){ string first, second; cin>>first>>second; vector<int> result(5001, 0); if(first.length()>second.length()) swap(first, second); //------------------------------- int i = 1; while(i<=first.length()){ result[i-1] += int(first[first.length()-i] - '0') + int(second[second.length()-i] - '0'); i++; result[i-1] = result[i-2]/10; result[i-2]%=10; } while(i<=second.length()){ result[i-1] += int(second[second.length()-i] - '0'); i++; result[i-1] = result[i-2]/10; result[i-2]%=10; } if(result[i-1]!=0) cout<<result[i-1]; for(int j=i-2; j>=0; j--) cout<<result[j]; return 0; } |
English