-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP711.java
More file actions
38 lines (32 loc) · 1.1 KB
/
P711.java
File metadata and controls
38 lines (32 loc) · 1.1 KB
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 p700_799;
import java.util.Scanner;
//accepted
public class P711 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = Integer.parseInt(sc.nextLine());
for (int i = 0; i < N; i++) {
String s = sc.nextLine();
int [] arr = new int[s.length()];
for (int j = 0; j < s.length(); j++) {
arr[j] = Integer.parseInt(s.charAt(j) + "");
}
int acumulador = 0;
int mayor=0;
for (int j = 0; j < arr.length; j++) {
if (j%2 == 0){
int min = 10;
for (int k = arr.length-1; k>j ; k--) {
min = arr[k]<min ? arr[k] : min;
if (min==0)break;
}
acumulador += 3*arr[j] + min; //+ el minimo que este a su derecha
} else {
acumulador += 2*arr[j] + mayor;
}
mayor=Math.max(mayor,arr[j]);
}
System.out.println(acumulador);
}
}
}