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

Envío 4636

Problema 0x30 - Incrementar un número muy grande

  • Autor: 7yrionLannister
  • Fecha: 2021-08-04 20:20:45 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.113 s 12 KBi
#2
Correcto
0.129 s 13 KBi
#3
Correcto
0.133 s 13 KBi
#4
Correcto
0.12 s 15 KBi
#5
Correcto
0.126 s 12 KBi
#6
Correcto
0.136 s 12 KBi
#7
Correcto
0.136 s 13 KBi
#8
Correcto
0.115 s 12 KBi
#9
Correcto
0.134 s 14 KBi
#10
Correcto
0.142 s 12 KBi
#11
Correcto
0.132 s 14 KBi
#12
Correcto
0.107 s 16 KBi
#13
Correcto
0.106 s 13 KBi
#14
Correcto
0.14 s 13 KBi
#15
Correcto
0.138 s 14 KBi
#16
Correcto
0.135 s 13 KBi
#17
Correcto
0.145 s 12 KBi
#18
Correcto
0.103 s 13 KBi
#19
Correcto
0.124 s 18 KBi
#20
Correcto
0.149 s 13 KBi
#21
Correcto
0.132 s 14 KBi
#22
Correcto
0.122 s 12 KBi
#23
Correcto
0.141 s 13 KBi
#24
Correcto
0.147 s 13 KBi
#25
Correcto
0.119 s 14 KBi
#26
Correcto
0.188 s 39 KBi
#27
Correcto
0.231 s 39 KBi
#28
Correcto
0.134 s 13 KBi
#29
Correcto
0.116 s 11 KBi
#30
Correcto
0.13 s 11 KBi
#31
Correcto
0.124 s 20 KBi
#32
Correcto
0.134 s 19 KBi
#33
Correcto
0.15 s 15 KBi
#34
Correcto
0.182 s 36 KBi
Puntos totales: 100 / 100

Código

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String num = br.readLine();
        bw.write(add(num, 1) + "\n");
        br.close();
        bw.close();
    }

    public static String add(String num, int addition) {
        int N = num.length();
        String result = "";
        int N1 = N - 1;
        int i;
        for (i = 0; i < N && addition != 0; i++) {
            int digit = num.charAt(N1 - i) - '0';
            digit += addition;
            if (digit >= 10 && i < N1) {
                addition = 1;
                digit -= 10;
            } else {
                addition = 0;
            }
            result = digit + result;
        }

        return num.substring(0, N - i) + result;
    }
}