1230 암호문3 문제 링크
문제분석
- I(삽입) x, y, s : 앞에서부터 x번째 암호문 바로 다음에 y개의 암호문을 삽입. s는 덧붙일 암호문들임.
- D(삭제) x, y : 앞에서부터 x번째 암호문 바로 다음부터 y개의 암호문을 삭제.
- A(추가) y, s : 암호문 뭉치 맨 뒤에 y개의 암호문을 덧붙임. s는 덧붙일 암호문들.
제약 사항
입력 조건
- 첫째 줄 : 원본 암호문 뭉치 속 암호문의 개수 N ( 2000 ≤ N ≤ 4000 의 정수)
- 둘째 줄 : 원본 암호문 뭉치
- 셋째 줄 : 명령어의 개수 ( 250 ≤ M ≤ 500 의 정수)
- 넷째 줄 : 명령어
출력 조건
- #부호 + 테스트 케이스 번호 + " " + 암호문 뭉치의 앞 10개 암호문을 출력
#1
import java.util.ArrayList;
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
for(int test_case = 1; test_case <= 10; test_case++)
{
int N = sc.nextInt();
ArrayList<Integer> code = new ArrayList<>(N);
for(int i=0; i<N; i++) {
code.add(sc.nextInt());
}
int count = sc.nextInt();
for(int c=0; c<count; c++) {
String a = sc.next();
if (a.equals("I")) {
int Index = sc.nextInt();
int N2 = sc.nextInt();
for(int i=0; i<N2; i++) {
code.add(Index+i, sc.nextInt());
}
} else if (a.equals("D")) {
int Index = sc.nextInt();
int N2 = sc.nextInt();
for(int i=0; i<N2; i++) {
code.remove(Index);
}
} else if (a.equals("A")) {
int N2 = sc.nextInt();
for(int i=0; i<N2; i++) {
code.add(sc.nextInt());
}
}
}
System.out.print("#" + test_case);
for(int i=0; i<10; i++) {
System.out.print(" " + code.get(i));
}
System.out.println();
}
}
}

5/7 다시 풀어봄
#2
2분
import java.util.*;
import java.io.FileInputStream;
class Solution
{
static char[][] arr;
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=10;
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
LinkedList<Integer> arr = new LinkedList<>();
for(int i=0; i<N; i++) {
arr.addLast(sc.nextInt());
}
int comNum = sc.nextInt();
for(int j=0; j<comNum; j++) {
String commend = sc.next();
int index = sc.nextInt();
if(commend.equals("I")) {
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
arr.add(index+i, sc.nextInt());
}
}
else if(commend.equals("D")) {
int count = sc.nextInt();
for(int i=0; i<count; i++) {
arr.remove(index);
}
}
else if(commend.equals("A")) {
for(int i=0; i<index; i++) {
arr.addLast(sc.nextInt());
}
}
}
System.out.print("#" + test_case + " ");
for(int i=0; i<10; i++) {
System.out.print(arr.get(i)+" ");
}
System.out.println();
}
}
}
