๊ธฐ๋ก๋ฐฉ

BOJ_2566 : ์ตœ๋Œ“๊ฐ’ ๋ณธ๋ฌธ

CodingTest/Java

BOJ_2566 : ์ตœ๋Œ“๊ฐ’

Soom_1n 2023. 1. 19. 23:44

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

 

2566๋ฒˆ: ์ตœ๋Œ“๊ฐ’

์ฒซ์งธ ์ค„์— ์ตœ๋Œ“๊ฐ’์„ ์ถœ๋ ฅํ•˜๊ณ , ๋‘˜์งธ ์ค„์— ์ตœ๋Œ“๊ฐ’์ด ์œ„์น˜ํ•œ ํ–‰ ๋ฒˆํ˜ธ์™€ ์—ด ๋ฒˆํ˜ธ๋ฅผ ๋นˆ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฐจ๋ก€๋กœ ์ถœ๋ ฅํ•œ๋‹ค. ์ตœ๋Œ“๊ฐ’์ด ๋‘ ๊ฐœ ์ด์ƒ์ธ ๊ฒฝ์šฐ ๊ทธ ์ค‘ ํ•œ ๊ณณ์˜ ์œ„์น˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net



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

  • 2์ฐจ์› ๋ฐฐ์—ด์—์„œ ์ตœ๋Œ€๊ฐ’๊ณผ ๊ทธ ์ธ๋ฑ์Šค๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = 0, y = 0, max = -1;

        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                int in = sc.nextInt();
                if (in > max) {
                    max = in;
                    x = i;
                    y = j;
                }
            }
        }
        System.out.println(max + "\n" + x + " " + y);
    }
}

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

  • ์ž…๋ ฅ ๊ฐ’์ด 0~90์ด๋ฏ€๋กœ ์ตœ๋Œ€๊ฐ’ max์˜ ์ดˆ๊ธฐ๊ฐ’์„ -1๋กœ ์„ค์ •ํ•œ๋‹ค.
    • x = 1, y = 1, max = 0 ์œผ๋กœ ํ•  ๋•Œ๋„, if๋ฌธ์„ ํ•œ ๋ฒˆ๋„ ์‹คํ–‰ํ•˜์ง€ ์•Š๋”๋ผ๋„ ํ†ต๊ณผ ๋  ๊ฒƒ ๊ฐ™๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ์˜€์ง€๋งŒ max๊ฐ’์„ 0์œผ๋กœ ๋„ฃ์œผ๋ฉด์„œ x,y๋ฅผ 0์œผ๋กœ ๋„ฃ์–ด์„œ 1ํšŒ ํ‹€๋ ธ๋‹ค.
  • ๋ฐฑ์ค€ ๋‹จ๊ณ„๋ณ„ ๋ฌธ์ œ์—์„œ 2์ฐจ์› ๋ฐฐ์—ด์˜ 2๋ฒˆ์งธ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค.

728x90

'CodingTest > Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_24060 : ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ˆ˜์—… - ๋ณ‘ํ•ฉ ์ •๋ ฌ 1  (0) 2023.01.23
BOJ_25501 : ์žฌ๊ท€์˜ ๊ท€์žฌ  (0) 2023.01.20
BOJ_25305 : ์ปคํŠธ๋ผ์ธ  (0) 2023.01.18
BOJ_2587 : ๋Œ€ํ‘œ๊ฐ’2  (0) 2023.01.17
BOJ_10610 : 30  (0) 2023.01.16