-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP143.java
More file actions
45 lines (37 loc) · 1.11 KB
/
P143.java
File metadata and controls
45 lines (37 loc) · 1.11 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
39
40
41
42
43
44
45
package p100_199;
import java.util.Scanner;
import java.util.Stack;
//accepted
public class P143 {
static void girar(int tortitasGiradas, Stack<Integer> tortitas){
int[] arr = new int[tortitasGiradas];
for (int j = 0; j < tortitasGiradas; j++) {
arr[j] = tortitas.pop();
}
for (int j = 0; j < tortitasGiradas; j++) {
tortitas.push(arr[j]);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<Integer> tortitas;
int m,x;
int n = sc.nextInt();
while (n!=-1) {
tortitas = new Stack<>();
while (n != -1) {
tortitas.push(n);
n = sc.nextInt();
}
m = sc.nextInt();
for (int i = 0; i < m; i++) {
x = sc.nextInt();
girar(x, tortitas);
}
System.out.println(tortitas.pop());
n = sc.nextInt();
tortitas.clear();
}
sc.close();
}
}