출처 : SW Expert Academy
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
어렵진 않은데 추가, 삭제 인덱스를 어떻게 지정해줘야하는지 모호해서 출력 결과보고 수정함
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=0; tc<10; tc++){
int n = sc.nextInt();
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<n; i++){
arr.add(sc.nextInt());
}
n = sc.nextInt();//명령어의 개수
for(int i=0; i<n; i++){
String str = sc.next();
if(str.equals("I")){
int idx = sc.nextInt();
int num = sc.nextInt();
for(int j=0; j<num; j++){
arr.add(++idx, sc.nextInt());
}
}else if(str.equals("D")){
int idx = sc.nextInt()+1;
int num = sc.nextInt();
for(int j=0; j<num; j++){
arr.remove(idx);
}
}else if(str.equals("A")){
int num = sc.nextInt();
for(int j=0; j<num; j++){
arr.add(sc.nextInt());
}
}
}
System.out.print("#" + (tc+1) + " ");
for(int i=0; i<10; i++){
System.out.print(arr.get(i) + " ");
}
System.out.println();
}
}
}
'알고리즘' 카테고리의 다른 글
[SWEA/JAVA] 4299. 태혁이의 사랑은 타이밍 (0) | 2024.11.14 |
---|---|
[SWEA/JAVA] 1979 어디에 단어가 들어갈 수 있을까 (2) | 2024.11.13 |
[SWEA/JAVA] 2001 파리퇴치 (0) | 2024.11.11 |
[백준/JAVA] 1966 프린터큐 (0) | 2024.11.10 |
[백준/JAVA] 9498 시험 성적 (2) | 2024.11.09 |