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

Envío 4256

Problema 0x30 - Incrementar un número muy grande

  • Autor: andres0608
  • Fecha: 2021-06-01 07:30:45 UTC (Hace 22 días)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.161 s 37 KBi
#2
Correcto
0.177 s 21 KBi
#3
Correcto
0.225 s 22 KBi
#4
Correcto
0.167 s 16 KBi
#5
Correcto
0.214 s 19 KBi
#6
Correcto
0.198 s 24 KBi
#7
Correcto
0.21 s 15 KBi
#8
Correcto
0.175 s 18 KBi
#9
Correcto
0.164 s 16 KBi
#10
Correcto
0.22 s 15 KBi
#11
Correcto
0.283 s 19 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.127 s 13 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.116 s 19 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.12 s 14 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.157 s 20 KBi
#16
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.156 s 20 KBi
#17
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.207 s 23 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.154 s 24 KBi
#19
Correcto
0.272 s 23 KBi
#20
Correcto
0.164 s 15 KBi
#21
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 8
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.184 s 16 KBi
#22
Correcto
0.219 s 14 KBi
#23
Correcto
0.168 s 16 KBi
#24
Correcto
0.287 s 22 KBi
#25
Correcto
0.151 s 15 KBi
#26
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10000
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.158 s 13 KBi
#27
Correcto
0.501 s 48 KBi
#28
Correcto
0.318 s 21 KBi
#29
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 10000
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:709)
	at Main.main(Main.java:13)
0.277 s 19 KBi
#30
Correcto
0.219 s 16 KBi
#31
Correcto
0.249 s 27 KBi
#32
Correcto
0.254 s 29 KBi
#33
Correcto
0.261 s 17 KBi
#34
Correcto
0.281 s 42 KBi
Puntos totales: 71 / 100

Código

import java.util.*;
public class Main {

      public static void main(String args[]){
		        
		    	Scanner inputData = new Scanner(System.in);
		        String numRowsColumns = inputData.nextLine();	
		        StringBuilder input = new StringBuilder();
		        input.append(numRowsColumns);
		        String inputReverse= input.reverse().toString();
		        int pos=0;
		        for(int i =0; i < numRowsColumns.length();i++) {
		        	if(inputReverse.charAt(i) == "9".charAt(0) && inputReverse.charAt(i+1)!="9".charAt(0)) {
		        		pos = (numRowsColumns.length() - i) -1;
		        		break;
		        	};
		        }
		        
		        pos = (pos==0)?1:pos;
		        
		        String part2= numRowsColumns.substring(pos-1);
		        int sw=0;
		        String valor1="";
		        String valor2="";
		        for(int j=part2.length()-1; j >=0; j--) {
		        	if(part2.charAt(j)=="9".charAt(0)) {
		        		sw=1;
		        		valor1+="0";
		        	}else {
		        		valor2= Integer.toString(Integer.parseInt(String.valueOf(part2.charAt(j)))+1);
		        		break;
		        	}
		        }

		        numRowsColumns = numRowsColumns.substring(0,pos-1);
		        System.out.println(((sw==0)?numRowsColumns+part2.substring(0,part2.length()-1)+valor2 + valor1:numRowsColumns + valor2 + valor1));
		    }
}