SWLUG/๋ฐฑ์ค€ BEAKJOON

[C] ๋ฐฑ์ค€/BAEKJOON 2566๋ฒˆ: ์ตœ๋Œ“๊ฐ’

waterproof 2023. 11. 15. 07:09

 

https://www.acmicpc.net/problem/2566

 

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

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

www.acmicpc.net

 



[2] ์ •๋‹ต ๋ฐ ํ•ด์„ค

 

#include <stdio.h>

int main() {
    int maxVal = 0, maxRow = 0, maxCol = 0;
    int grid[9][9];

    // ๊ฒฉ์žํŒ ์ž…๋ ฅ
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            scanf("%d", &grid[i][j]);

            // ์ตœ๋Œ“๊ฐ’ ๊ฐฑ์‹ 
            if (grid[i][j] > maxVal) {
                maxVal = grid[i][j];
                maxRow = i;
                maxCol = j;
            }
        }
    }

    // ๊ฒฐ๊ณผ ์ถœ๋ ฅ
    printf("%d\n%d %d\n", maxVal, maxRow + 1, maxCol + 1);

    return 0;
}

 

 

 

  1. maxVal, maxRow, maxCol: ์ตœ๋Œ“๊ฐ’๊ณผ ํ•ด๋‹น ์ตœ๋Œ“๊ฐ’์ด ์œ„์น˜ํ•œ ํ–‰ ๋ฒˆํ˜ธ, ์—ด ๋ฒˆํ˜ธ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜๋“ค์ด๋‹ค.
  2. grid[9][9]: 9x9 ํฌ๊ธฐ์˜ ๊ฒฉ์žํŒ์„ ๋‚˜ํƒ€๋‚ด๋Š” 2์ฐจ์› ๋ฐฐ์—ด์ด๋‹ค.
  3. ๊ฒฉ์žํŒ์„ ์ž…๋ ฅํ•˜๋Š” ์ค‘์—, ์ตœ๋Œ“๊ฐ’(maxVal)์ด ๊ฐฑ์‹ ๋  ๋•Œ๋งˆ๋‹ค ์ตœ๋Œ“๊ฐ’์„ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜๋“ค(maxRow, maxCol)์„ ์—…๋ฐ์ดํŠธํ•œ๋‹ค.
  4. ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•  ๋•Œ, ์ตœ๋Œ“๊ฐ’๊ณผ ์œ„์น˜ํ•œ ํ–‰ ๋ฒˆํ˜ธ, ์—ด ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ํ–‰ ๋ฒˆํ˜ธ์™€ ์—ด ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ, ์ถœ๋ ฅ ์‹œ์—๋Š” ๊ฐ๊ฐ 1์„ ๋”ํ•ด์ค€๋‹ค.

 

 


[3] ๋Š๋‚€ ์ 

 

 

2์ฐจ์› ๋ฐฐ์—ด๋„ ์‚ฌ์šฉํ•˜๋ฉด์„œ, ์ตœ๋Œ“๊ฐ’์„ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜'๋“ค'๋„ ์—…๋ฐ์ดํŠธ ํ•ด์•ผ ํ•ด์„œ ๋จธ๋ฆฌ๊ฐ€ ์•„ํŒ ๋‹ค ๐Ÿฅน