๐Ÿ‘ฉโ€๐Ÿ’ป SWEA_1225_์•”ํ˜ธ์ƒ์„ฑ๊ธฐ

๐Ÿ’ฌ ๋ฌธ์ œ๋ฅผ ๊ผผ๊ผผํ•˜๊ฒŒ ์ฝ์ง€์•Š์•„์„œ ๋†“์น˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ’ก ํ’€์ด ๋ฐฉ๋ฒ•

  • ์ˆซ์ž๋ฅผ ๋„ฃ์—ˆ๋‹ค ๋นผ๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ˆ, Queue ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ด์•˜์Šต๋‹ˆ๋‹ค.
  • ํ•œ ์‚ฌ์ดํด ์ด๋ผ๋Š” ํ‘œํ˜„์„ ๋†“์ณ ์˜ค๋‹ต์ด ์ถœ๋ ฅ๋์Šต๋‹ˆ๋‹ค.
    - cycle์ด 5๋ฅผ ๋„˜์œผ๋ฉด ๋นผ์ฃผ๋Š” ๊ฐ’(=cnt)๊ณผ cycle์„ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ฅ ์ฝ”๋“œ

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class SWEA_1225_์•”ํ˜ธ์ƒ์„ฑ๊ธฐ {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		for (int t = 1; t <= 10; t++) {
			int T = sc.nextInt();
			int cnt = 0;
			int cycle = 0;
			Queue<Integer> password = new LinkedList<>();
			for (int i = 0; i < 8; i++) {
				password.add(sc.nextInt());
			}
			while (true) {
				cnt++;
				cycle++;
				if (cycle == 6) {
					cycle = 1;
					cnt = 1;
				}
				if (password.peek() - cnt <= 0) {
					password.poll();
					password.add(0);
					break;
				}
				int tmp = password.poll() - cnt;
				password.add(tmp);
			}
			System.out.print("#" + T);
			for (int i = 0; i < 8; i++) {
				System.out.print(" ");
				System.out.print(password.poll());
			}
			System.out.println();
		}
	}

}

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ