728x90
반응형
풀이 :
LinkedList<Integer> 써서 add 사용. x번째 다음에 수를 입력하려면, .add(x, 숫자) 로 하면 됨.
Code
public class Solution1228 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
for (int tc = 1; tc <= 10; tc++) {
LinkedList<Integer> list = new LinkedList<Integer>();
int N = sc.nextInt(); // 암호문 개수
for (int i = 0; i < N; i++) { // 암호문 넣기
list.add(sc.nextInt());
}
int M = sc.nextInt();
for (int i = 0; i < M; i++) {
char command = sc.next().charAt(0);
if (command == 'I') {
int x = sc.nextInt(); // x의 위치 바로 다음에 y개의 숫자를 삽입
int y = sc.nextInt();
for (int j = 0; j < y; j++) {
list.add(x + j, sc.nextInt()); // x++ 로 해도 무방
}
}
}
System.out.print("#" + tc + " ");
for (int i = 0; i < 10; i++) {
System.out.print(list.get(i) + " ");
}
}
}
}
728x90
반응형
'SWEA' 카테고리의 다른 글
swea 1234 [D3] [S/W 문제해결 기본] 10일차 - 비밀번호 JAVA (2) | 2023.11.24 |
---|---|
swea 1230 [D3] [S/W 문제해결 기본] 8일차 - 암호문3 JAVA (1) | 2023.11.24 |
swea 1225 [D3] [S/W 문제해결 기본] 7일차 - 암호생성기 JAVA (1) | 2023.11.24 |
swea 1221 [D3] [S/W 문제해결 기본] 5일차 - GNS JAVA (1) | 2023.11.24 |
swea 1220 [D3] [S/W 문제해결 기본] 5일차 - Magnetic JAVA (1) | 2023.11.24 |