java
0 ~ 999999 사이의 수로 표현되는 암호문이 있고, 이 암호문을 N개 모아 놓은 암호문 뭉치가 있다.
암호문 뭉치를 급히 수정해야 할 일이 발생했는데, 다음과 같이 3개의 명령어로 제어한다.
위의 규칙에 맞게 작성된 명령어를 나열하여 만든 문자열이 주어졌을 때, 암호문 뭉치를 수정하고, 수정된 결과의 처음 10개 암호문을 출력하는 문제
LinkedList 를 활용해 문제를 풀었다.
LinkedList 를 활용한 여러 문제들을 더 풀어볼 계획이다.
import java.util.Scanner;
import java.io.FileInputStream;
import java.util.List;
import java.util.LinkedList;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = 10;
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
List<Integer> list = new LinkedList<>();
for (int i = 0; i < N; i++) {
list.add(sc.nextInt());
}
int commandCount = sc.nextInt();
for (int i = 0; i < commandCount; i++) {
String command = sc.next();
switch (command) {
case "I":
int x = sc.nextInt();
int y = sc.nextInt();
for (int j = 0; j < y; j++) {
list.add(x + j, sc.nextInt());
}
break;
case "D":
x = sc.nextInt();
y = sc.nextInt();
for (int j = 0; j < y; j++) {
list.remove(x);
}
break;
case "A":
y = sc.nextInt();
for (int j = 0; j < y; j++) {
list.add(sc.nextInt());
}
break;
}
}
System.out.print("#" + test_case + " ");
for (int i = 0; i < 10 && i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
System.out.println();
}
}
}
JavaReadable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
테스트 시 의존성 주입(Dependency Injection)과 Mockito Spring 애플리케이션을 개발하다 보면, 테스트 코드에서 실제 빈(Bean)을 사용하지…
들어가며 스프링 기반 프로젝트에서 좋은 설계 구조와 테스트 전략은 소프트웨어 품질과 유지보수성에 직결됩니다. 최근 학습한…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…