-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
34 lines (29 loc) · 948 Bytes
/
Solution.java
File metadata and controls
34 lines (29 loc) · 948 Bytes
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
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
private static final Scanner sc = new Scanner(System.in);
private static List<Integer> list = new ArrayList<>();
public static void main(String[] args) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
list.add(sc.nextInt());
}
int q = sc.nextInt();
for (int i = 0; i < q; i++) {
String op = sc.next();
if (op.equalsIgnoreCase("insert")) {
list.add(sc.nextInt(), sc.nextInt());
} else if (op.equalsIgnoreCase("delete")) {
list.remove(sc.nextInt());
} else {
System.out.println("Error: invalid operation!");
System.exit(1);
}
}
sc.close();
for (Integer num : list) {
System.out.printf("%d ", num);
}
}
}