SWEA1228 암호문1

주어진 조건대로 실행되도록 LinkedList를 활용해 구현하는 문제다.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Solution {
	static BufferedReader br;
	static BufferedWriter bw;
	static StringTokenizer st;
	static LinkedList<Integer> lkdList;

	public static void main(String[] args) throws IOException {

		br = new BufferedReader(new InputStreamReader(System.in));
		bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int T = 10;
		for (int tc = 1; tc <= T; tc++) {
			int N = Integer.parseInt(br.readLine());
			st = new StringTokenizer(br.readLine(), " ");
			lkdList = new LinkedList<>();
			for (int i = 0; i < N; i++) {
				lkdList.offer(Integer.parseInt(st.nextToken()));
			}
			// 명령어 입력받기
			N = Integer.parseInt(br.readLine());
			st = new StringTokenizer(br.readLine(), " ");
			while (st.hasMoreElements()) {
				st.nextToken();
				int x = Integer.parseInt(st.nextToken());
				int y = Integer.parseInt(st.nextToken());

				for (int i = x; i < x + y; i++) {
					lkdList.add(i, Integer.parseInt(st.nextToken()));
				}
			}					
			bw.write(String.format("#%d", tc));			
			for(int i = 0; i < 10; i++) {
				bw.write(String.format(" %d", lkdList.get(i)));
			}
			bw.write("\n");
		}
		bw.flush();
		bw.close();
	}

}

좋은 웹페이지 즐겨찾기