본문 바로가기
알고리즘

[SWEA/JAVA] 1230 암호문3

by writing turtle 2024. 11. 12.

출처 : 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();
		}
	}
}