큐를 사용한 구현
poll(), offer(), clear()
package D3;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class 암호생성기 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cnt = 0;
boolean find = false;
Queue<Integer> queue = new LinkedList<>();
for(int tc = 1; tc<=10; tc++) {
int N =sc.nextInt(); // 그냥 숫자
find = false;
// 8개의 데이터
for(int i =0; i<8; i++) {
queue.offer(sc.nextInt());
}
int tmp =0;
while(true) {
for(int i=1; i<=5; i++) {
int a = queue.poll();
int b = a-i;
if(b <0 || b == 0) {
b = 0;
queue.offer(b);
find = true;
break;
}else {
queue.offer(b);
}
}
if(find) {
break;
}
}
System.out.print("#" + tc + " ");
for(int i =0; i<8; i++) {
System.out.print(queue.poll()+" ");
}
System.out.println();
queue.clear(); // 큐에 모든내용 지우기
}
}
}
'알고리즘 > SwExpert recipe' 카테고리의 다른 글
[SWEA] 쥬스나누기 D3 (0) | 2021.03.05 |
---|---|
[SWEA] 소득 불균형 D3 (0) | 2021.03.01 |
[SWEA] 원재의 메모리 복구 D3 (0) | 2021.03.01 |
[SWEA] 회문 D3 (0) | 2021.03.01 |
[SWEA] 거듭제곱 [D3] (0) | 2021.02.24 |