█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6765

Problema 0x31 - Sumarle un dígito a número muy grande

  • Autor: danidiaztech
  • Fecha: 2022-11-15 00:23:36 UTC (Hace alrededor de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 1 KBi
#2
Correcto
0.006 s 2 KBi
#3
Correcto
0.004 s 1 KBi
#4
Correcto
0.005 s 1 KBi
#5
Correcto
0.004 s 1 KBi
#6
Correcto
0.004 s 19 KBi
#7
Correcto
0.005 s 1 KBi
#8
Correcto
0.007 s 1 KBi
#9
Correcto
0.005 s 1 KBi
#10
Correcto
0.004 s 1 KBi
#11
Correcto
0.005 s 1 KBi
#12
Correcto
0.005 s 1 KBi
#13
Correcto
0.004 s 6 KBi
#14
Correcto
0.007 s 1 KBi
#15
Correcto
0.004 s 1 KBi
#16
Correcto
0.004 s 1 KBi
#17
Correcto
0.005 s 1 KBi
#18
Correcto
0.007 s 1 KBi
#19
Correcto
0.005 s 1 KBi
#20
Correcto
0.004 s 23 KBi
#21
Correcto
0.004 s 5 KBi
#22
Correcto
0.004 s 10 KBi
#23
Correcto
0.004 s 1 KBi
#24
Correcto
0.004 s 2 KBi
#25
Correcto
0.005 s 1 KBi
#26
Correcto
0.005 s 2 KBi
#27
Correcto
0.005 s 1 KBi
#28
Correcto
0.005 s 1 KBi
#29
Correcto
0.005 s 1 KBi
#30
Correcto
0.005 s 1 KBi
#31
Correcto
0.005 s 1 KBi
#32
Correcto
0.005 s 1 KBi
#33
Correcto
0.005 s 1 KBi
#34
Correcto
0.005 s 1 KBi
#35
Correcto
0.004 s 3 KBi
#36
Correcto
0.006 s 1 KBi
#37
Correcto
0.005 s 2 KBi
#38
Correcto
0.006 s 2 KBi
#39
Correcto
0.005 s 1 KBi
#40
Correcto
0.005 s 1 KBi
#41
Correcto
0.006 s 1 KBi
#42
Correcto
0.006 s 1 KBi
Puntos totales: 100 / 100

Código

// Made by Daniel Diaz (@Danidiaztech)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define forn(i, n) for (int i = 0; i < n; i++) // for in range in python
#define FOR(i, a, b) for (int i = a; i < b; i++) // for in range in python
#define int long long int
#define double long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair

typedef pair<int, int> pii;

const int MAX = 1e6;
const int MIN = -MAX;
const int INF = LLONG_MAX;
const int MINF = LLONG_MIN;
const int MOD = 1e9 + 7;

// int arr[MAX];
void solve(){
  string x, k;
  cin >> x >> k;
  int n1, n2;
  n1 = (int)x.size();
  n2 = (int)k.size();
  vector<int> X;
  vector<int> K;


  for (int i = n1 -1 ; i >= 0; i--){
    // Push numbers backwards
    X.pb((int)(x[i]- '0'));
  }
  for (int i = n2 -1 ; i >= 0; i--){
    // Push numbers backwards
    K.pb((int)(k[i] - '0'));
  }
   
  // O(n)
  // Add k to x
  int i;
  int j = 0;
  int remainder = 0;
  for (i = 0; i < n2; i++){
    if (i < n1){
      int s = X[i] + K[i] + remainder;
      if (s >= 10){
        X[i] = s % 10;
        remainder = 1;
        j++;
      }
      else{
        X[i] = s;
        remainder = 0;
        break;
      }
    }
  }
  if (remainder != 0){
    while (i < max(n1, n2)){
      int s = remainder + X[i]; 
      if (s >= 10){
        X[i] = s % 10;
        remainder = 1;
      }
      else{
        X[i] = s;
        remainder = 0;
        break;
      }
      i++;
    }
    if (remainder != 0) cout << remainder;
  }
  // Print -  answer must be in X
  for (int i = (int)X.size() - 1; i >= 0; i--){
    cout << X[i];
  }
}

int32_t main() {
  fastInp;
  #if LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int tc = 1;
  // cin >> tc;

  for (int t = 1; t <= tc; t++){
    // cout << "Case #" << t << ": ";
    solve();
  }
  return 0;
}