๊ธฐ๋ก๋ฐฉ

BOJ_1476 : ๋‚ ์งœ ๊ณ„์‚ฐ ๋ณธ๋ฌธ

CodingTest/Java

BOJ_1476 : ๋‚ ์งœ ๊ณ„์‚ฐ

Soom_1n 2022. 10. 3. 18:17

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

1476๋ฒˆ: ๋‚ ์งœ ๊ณ„์‚ฐ

์ค€๊ทœ๊ฐ€ ์‚ฌ๋Š” ๋‚˜๋ผ๋Š” ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์—ฐ๋„์™€ ๋‹ค๋ฅธ ๋ฐฉ์‹์„ ์ด์šฉํ•œ๋‹ค. ์ค€๊ทœ๊ฐ€ ์‚ฌ๋Š” ๋‚˜๋ผ์—์„œ๋Š” ์ˆ˜ 3๊ฐœ๋ฅผ ์ด์šฉํ•ด์„œ ์—ฐ๋„๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ๊ฐ๊ฐ์˜ ์ˆ˜๋Š” ์ง€๊ตฌ, ํƒœ์–‘, ๊ทธ๋ฆฌ๊ณ  ๋‹ฌ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ง€๊ตฌ๋ฅผ ๋‚˜ํƒ€

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • ์„ธ ์ˆซ์ž E, S, M์ด 1์”ฉ ์ฆ๊ฐ€ํ•˜๋‹ค๊ฐ€ ๊ฐ๊ฐ 16, 29, 20์ด ๋˜๋ฉด 1์ด ๋œ๋‹ค.
  • ์ž…๋ ฅ๋œ ๋ชฉํ‘œ๊ฐ€ ๋  ๋•Œ๊นŒ์ง€ ๋ช‡๋ฒˆ ์ฆ๊ฐ€ํ•ด์•ผํ•˜๋Š”์ง€ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int e = Integer.parseInt(st.nextToken());
        int s = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        int ee = 1, ss = 1, mm = 1, answer = 1;
        while (!(ee == e && ss == s && mm == m) && answer < 10000){
            answer++;
            if (++ee == 16) ee = 1;
            if (++ss == 29) ss = 1;
            if (++mm == 20) mm = 1;
        }
        System.out.println(answer);
    }
}

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • ์ž…๋ ฅ๋œ ๋ชฉํ‘œ๊นŒ์ง€ while๋ฌธ์œผ๋กœ ๊ณ„์‚ฐ์„ ๋ฐ˜๋ณตํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ์ด์ œ๋ณด๋‹ˆ ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด์ปค์ ธ์„œ ํ™•์ธ์„ ํŽธํ•˜๊ฒŒํ•˜๊ธฐ ์œ„ํ•ด while๋ฌธ์— 10000๋ฒˆ ์ œํ•œ์„ ๋’€๋Š”๋ฐ ์ง€์šฐ์ง€ ์•Š๊ณ  ์ œ์ถœํ–ˆ๋‹ค.
  • ์ฒ˜์Œ์—” ee, ss, mm์„ ๋‚˜๋จธ์ง€ ๊ณ„์‚ฐ ์ˆ˜์‹์„ ์ž˜ ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์•˜๋Š”๋ฐ, ๋” ๊ฐ„๋‹จํžˆ ํ’€๋ฆฌ๋Š” ๋ฌธ์ œ์˜€๋‹ค.

728x90