|
| 1 | +```java |
| 2 | +import java.util.*; |
| 3 | + |
| 4 | +import javax.xml.parsers.*; |
| 5 | + |
| 6 | +import org.xml.sax.helpers.DefaultHandler; |
| 7 | + |
| 8 | +import java.io.*; |
| 9 | + |
| 10 | +public class Solution { |
| 11 | + |
| 12 | + public static void main(String[] args) throws Exception { |
| 13 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 14 | + |
| 15 | + StringBuilder sb = new StringBuilder(); |
| 16 | + for(int t = 1; t <= 10; t++) { |
| 17 | + int N = Integer.parseInt(br.readLine()); |
| 18 | + |
| 19 | + ArrayList<Integer> list = new ArrayList<>(); |
| 20 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 21 | + |
| 22 | + for(int i = 0; i < N; i++) { |
| 23 | + |
| 24 | + list.add(Integer.parseInt(st.nextToken())); |
| 25 | + } |
| 26 | + |
| 27 | + int M = Integer.parseInt(br.readLine()); |
| 28 | + |
| 29 | + st = new StringTokenizer(br.readLine()); |
| 30 | + for(int i = 0; i < M; i++) { |
| 31 | + |
| 32 | + char c = st.nextToken().charAt(0); |
| 33 | + |
| 34 | + if(c == 'I') { |
| 35 | + int x = Integer.parseInt(st.nextToken()); |
| 36 | + int y = Integer.parseInt(st.nextToken()); |
| 37 | + |
| 38 | + ArrayList<Integer> lis = new ArrayList<>(); |
| 39 | + |
| 40 | + for(int j = 0; j < y; j++) lis.add(Integer.parseInt(st.nextToken())); |
| 41 | + |
| 42 | + for(int j = lis.size() - 1; j >= 0; j--) { |
| 43 | + list.add(x, lis.get(j)); |
| 44 | + } |
| 45 | + |
| 46 | + } else if(c == 'D') { |
| 47 | + int x = Integer.parseInt(st.nextToken()); |
| 48 | + int y = Integer.parseInt(st.nextToken()); |
| 49 | + while(y --> 0) |
| 50 | + list.remove(x); |
| 51 | + } else { |
| 52 | + int y = Integer.parseInt(st.nextToken()); |
| 53 | + ArrayList<Integer> lis = new ArrayList<>(); |
| 54 | + |
| 55 | + for(int j = 0; j < y; j++) lis.add(Integer.parseInt(st.nextToken())); |
| 56 | + |
| 57 | + list.addAll(lis); |
| 58 | + } |
| 59 | + } |
| 60 | + sb.append("#").append(t).append(" "); |
| 61 | + |
| 62 | + for(int i = 0; i < 10; i++) sb.append(list.get(i)).append(" "); |
| 63 | + |
| 64 | + sb.append("\n"); |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | + System.out.println(sb); |
| 69 | + } |
| 70 | + |
| 71 | +} |
| 72 | +``` |
0 commit comments