Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- char x1[100100],y1[100100];
- cin >> x1 >> y1;
- int x = strlen(x1),y = strlen(y1);
- if(x>y){
- for(int i=0;i<y;++i){
- int a=x1[x-1-i]-'0';
- int b=y1[y-1-i]-'0';
- int c=a+b;
- if(c>=10){
- if(x-1-i==0){
- c=c-10;
- cout << "1";
- }
- else{
- c=c-10;
- x1[x-2-i]++;
- }
- }
- x1[x-1-i]=c+'0';
- }
- for(int i=x-1;i>=0;--i){
- if(x1[i]>=58){
- if(i==0){
- cout << "1";
- x1[i]=x1[i]-10;
- }
- else{
- x1[i-1]++;
- x1[i]=x1[i]-10;
- }
- }
- }
- cout << x1;
- }
- else{
- for(int i=0;i<x;++i){
- int a=y1[y-1-i]-'0';
- int b=x1[x-1-i]-'0';
- int c=a+b;
- if(c>=10){
- if(y-1-i==0){
- c=c-10;
- cout << "1";
- }
- else{
- c=c-10;
- y1[y-2-i]++;
- }
- }
- y1[y-1-i]=c+'0';
- }
- for(int i=y-1;i>=0;--i){
- if(y1[i]>=58){
- if(i==0){
- cout << "1";
- y1[i]=y1[i]-10;
- }
- else{
- y1[i-1]++;
- y1[i]=y1[i]-10;
- }
- }
- }
- cout << y1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement