πŸ‘©β€πŸ’» SWEA_1225_μ•”ν˜Έμƒμ„±κΈ°

YOU KNOW I MEANΒ·2021λ…„ 4μ›” 26일
0
post-thumbnail

πŸ’¬ 문제λ₯Ό κΌΌκΌΌν•˜κ²Œ μ½μ§€μ•Šμ•„μ„œ λ†“μΉ˜λŠ” 뢀뢄이 μžˆμ—ˆμŠ΅λ‹ˆλ‹€.


πŸ’‘ 풀이 방법

  • 숫자λ₯Ό λ„£μ—ˆλ‹€ λΉΌλŠ” μž‘μ—…μ΄ ν•„μš”ν•˜λ‹ˆ, 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();
		}
	}

}

0개의 λŒ“κΈ€

κ΄€λ ¨ μ±„μš© 정보