-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp348.java
38 lines (34 loc) · 1.28 KB
/
p348.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.caiomed03.aceptaelreto;
import java.util.Scanner;
public class p348 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int casosPrueba = sc.nextInt();
for (int i = 0; i < casosPrueba; i++) {
int n = sc.nextInt();
if (9 > n) {
System.out.println(1);
} else {
int tamaño = String.valueOf(n).length();
int factor;
if(tamaño%2==0){
String aux = "1" + String.valueOf((int) Math.pow(10, tamaño/2-1));
factor = Integer.parseInt(aux);
}
else{
factor = (int) Math.pow(10, (tamaño-1)/2);
}
String aux = String.valueOf(n);
int descRec;
if(factor*Integer.parseInt(aux.substring(0, aux.length()-1))<n){
descRec = n - factor*Integer.parseInt(aux.substring(0, aux.length()-1));
}
else{
descRec = n - factor*Integer.parseInt(aux.substring(0, aux.length()-1));
}
int res = Math.abs(factor+n-descRec);
System.out.println(res);
}
}
}
}