[SWEA] 암호문1

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

명령어 I는 arrayList의 인덱스를 지정하여 위치를 정해줄 수 있는 add 함수를 사용하여 해결한다.

1
aList.add(x+(index++), sc.nextInt()

JAVA Code

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
import java.util.ArrayList;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int tc=1; tc<=10; tc++) {
			ArrayList<Integer> aList = new ArrayList<>();
			int N = sc.nextInt();
			for(int i=0; i<N; i++) {
				aList.add(sc.nextInt());
			}
			
			int M = sc.nextInt(); // 명령어의 갯수
			for(int i=0; i<M; i++) {
				int index = 0;
				String c = sc.next();
				int x = sc.nextInt();
				int y = sc.nextInt();
				for(int j=0; j<y; j++) { 
					aList.add(x+(index++), sc.nextInt());
				}
			}
			
			System.out.print("#"+tc+" ");
			for(int i=0; i<10; i++) {
				System.out.print(aList.get(i)+" ");
			}
			System.out.println();
		}
	}
}