728x90

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14uWl6AF0CFAYD 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

문제)

 

 

 

 

풀이)

 

Queue를 알고 있다면 간단한 문제다.

숫자를 큐에서 차례로 뽑으면서 1부터 5까지 빼고 다시 큐에 삽입하는 작업을 한다.

이때, 뺀 수가 0보다 같거나 작을 경우 0을 큐에 삽입한 후 종료한다.

 

//import java.io.FileInputStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Solution_D3_1225_암호생성기 {

	public static void main(String[] args) throws Exception {
		//System.setIn(new FileInputStream("input2.txt"));
		Scanner sc = new Scanner(System.in);
		for(int test_case = 1; test_case <= 10; test_case++){
			int t = sc.nextInt();
			Queue<Integer> queue = new LinkedList<>();
			for(int i=0; i<8; i++)
				queue.offer(sc.nextInt());
			
			int check = 0;
			int num = 1;
			while(true) {
				int pop_num = queue.poll();
				check = pop_num-num;
				
				if(check <= 0){
					check = 0;
					queue.offer(check);
					break;
				}
				
				queue.offer(check);
				num++;
				if(num == 6)
					num=1;
			}
			
			System.out.print("#"+test_case+" ");
			for(int j=0; j<8; j++) {
				System.out.print(queue.poll() + " ");
			}	
			System.out.println();
		}
		sc.close();
	}
}

 

 

 

 

 

 

 

 

728x90

'코테 > SWEA' 카테고리의 다른 글

SWEA 9229 한빈이와 SpotMart  (0) 2022.08.20
SWEA 1228 암호문1(JAVA)  (0) 2022.08.19
SWEA 2001. 파리퇴치(JAVA, Python)  (0) 2022.08.16
SWEA 1218. 괄호 짝짓기(JAVA)  (0) 2022.08.12
SWEA 2805. 농작물 수확하기(JAVA)  (0) 2022.08.12

+ Recent posts