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

Envío 5040

Problema 0x30 - Incrementar un número muy grande

  • Autor: Camilo15
  • Fecha: 2021-10-07 16:23:38 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#2
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#3
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#4
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#5
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#6
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#7
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#8
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#9
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#10
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#11
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#12
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#13
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#14
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#15
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#16
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#17
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#18
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#19
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#20
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#21
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#22
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#23
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#24
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#25
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#26
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#27
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#28
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#29
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#30
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#31
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#32
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#33
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
#34
Error de compilación
                      Main.java:7: error: class Ideone is public, should be declared in a file named Ideone.java
public class Ideone {
       ^
1 error

                    
Puntos totales: 0 / 100

Código

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

public class Ideone {

    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);

        String number = sc.nextLine();
        String v[] = number.split("");
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < number.length(); i++) {
            list.add(Integer.parseInt(v[i]));
        }
        // int v[] = {7,9,5,9,9};
        System.out.println(sumOne(list));
    }

    public static String sumOne(ArrayList<Integer> list) {

        for (int i = list.size()-1; i >= 0; i--) {
            int value = list.get(i);
            if(value==9 && i>0){
                list.set(i, 0);
            } 
            else{
               list.set(i, value+1);
               return listToString(list);
            }
        }
        
        return listToString(list);
    }

    public static String listToString(ArrayList<Integer> list) {
        String st = "";
        for (int numb : list) {
            st+=numb;
        }
        return st;
    }
}