위의 규칙에 맞게 작성된 명령어를 나열하여 만든 문자열이 주어졌을 때, 암호문을 수정하고, 수정된 결과의 처음 10개 숫자를 출력하는 프로그램을 작성하여라.
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);
/*int T;
T=sc.nextInt();*/
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();
int Index = sc.nextInt();
int N2 = sc.nextInt();
for(int i=0; i<N2; i++) {
code.add(Index, sc.nextInt());
}
}
System.out.print("#" + test_case);
for(int i=0; i<10; i++) {
System.out.print(" " + code.get(i));
}
System.out.println();
}
}
}
code.add(Index, sc.nextInt());로 계속 같은 자리에 넣으니까 결과가 이상하지... code.add(Index+i, sc.nextInt());로 수정
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);
/*int T;
T=sc.nextInt();*/
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();
int Index = sc.nextInt();
int N2 = sc.nextInt();
for(int i=0; i<N2; i++) {
code.add(Index+i, sc.nextInt());
}
for(int i=0; i<10; i++) {
System.out.print(code.get(i)+"\n" );
}
System.out.println("aaaaaaaaa");
}
System.out.print("#" + test_case);
for(int i=0; i<10; i++) {
System.out.print(" " + code.get(i));
}
System.out.println();
}
}
}

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();
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
arr.add(index+i, sc.nextInt());
}
}
System.out.print("#" + test_case + " ");
for(int i=0; i<10; i++) {
System.out.print(arr.get(i)+" ");
}
System.out.println();
}
}
}
