Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <string.h>
  12.  
  13. using namespace std;
  14.  
  15. struct Number {
  16.     vector <int> Num;
  17.     void Initial (string InputNumber) {
  18.         for (int i = InputNumber.length() - 1; i >= 0; i--) {
  19.             Num.push_back(InputNumber[i] - '0');
  20.         }
  21.     }
  22.     /*static void Sum (Number Num1, Number Num2) {
  23.         Number Result;
  24.         Result.Num.resize(max(Num1.Num.size(), Num2.Num.size()) + 1);
  25.     }*/
  26. };    
  27.  
  28. int main()
  29. {
  30.     string InputNumber1, InputNumber2;
  31.     int MinLength, MaxLength;
  32.     cin >> InputNumber1;
  33.     cin >> InputNumber2;
  34.     Number Num1;
  35.     Num1.Initial(InputNumber1);
  36.     Number Num2;
  37.     Num2.Initial(InputNumber2);
  38.     Number Num3;
  39.     Num3.Num.resize(max(Num1.Num.size(), Num2.Num.size()) + 1);
  40.     if(Num1.Num.size() >= Num2.Num.size()) {
  41.         MinLength = Num2.Num.size();
  42.         MaxLength = Num1.Num.size();
  43.         for(int i = 0; i < MinLength; i++) {
  44.             Num3.Num.push_back(Num1.Num[i] + Num2.Num[i]);
  45.         }
  46.         for(int i = MinLength; i < MaxLength; i++) {
  47.             Num3.Num.push_back(Num1.Num[i]);
  48.         }
  49.     }
  50.     else {
  51.         MinLength = Num1.Num.size();
  52.         MaxLength = Num2.Num.size();
  53.         for(int i = 0; i < MinLength; i++) {
  54.             Num3.Num.push_back(Num1.Num[i] + Num2.Num[i]);
  55.         }
  56.         for(int i = MinLength; i < MaxLength; i++) {
  57.             Num3.Num.push_back(Num2.Num[i]);
  58.         }
  59.     }
  60.     for(int i = 0; i < MaxLength; i++) {
  61.         if (Num3.Num[i] / 2 != 0) {
  62.             Num3.Num[i + 1] = 1 % Num3.Num[i];
  63.         }
  64.     }
  65.     int i = Num3.Num.size() - 1;
  66.     while(Num3.Num[i] == 0) {
  67.         Num3.Num.pop_back();
  68.         i--;
  69.     }
  70.     for(int i = Num3.Num.size() - 1; i >= 0; i--) {
  71.         cout << Num3.Num[i];
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement