๐Ÿ‘ฉ‍๐Ÿ’ปProgramming/Coding Test

[C#] [BOJ#2562] ์ตœ๋Œ“๊ฐ’

taesooya 2022. 7. 30.

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

 

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

9๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ์ด๋“ค ์ค‘ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ๊ณ  ๊ทธ ์ตœ๋Œ“๊ฐ’์ด ๋ช‡ ๋ฒˆ์งธ ์ˆ˜์ธ์ง€๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋กœ ๋‹ค๋ฅธ 9๊ฐœ์˜ ์ž์—ฐ์ˆ˜ 3, 29, 38, 12, 57, 74, 40, 85, 61 ์ด ์ฃผ์–ด

www.acmicpc.net

My Solution

์ด์ „ ๊ฐ’์ด ์ดํ›„ ๊ฐ’ ๋ณด๋‹ค ํด ๊ฒฝ์šฐ๋กœ ์ƒ๊ฐํ–ˆ์Œ


    using System;
    using System.Text;

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                StringBuilder sb = new StringBuilder();
                int[] arr = new int[9];
                ~~int max = arr[0];~~
                int count = 0;
                for (int i = 0; i < 9; i++)
                {
                    arr[i] = Convert.ToInt32(Console.ReadLine());
                    ~~if (max < arr[i])~~
                    {
                        ~~max = arr[i];~~
                        ~~count++;~~
                    }
                }
                Array.Sort(arr);
                Console.WriteLine(arr[8] + "\\n" + count);
            }
        
        }

    }

My Solution

ํด ๊ฒฝ์šฐ๊ฐ€ ์•„๋‹ˆ๋ผ ์ž‘์„ ๊ฒฝ์šฐ ์นด์šดํŠธ๋ฅผ ์ƒˆ๊ณ 

max = int[0]๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ max<arr[i]์ผ ๊ฒฝ์šฐ int[i]๋กœ ๊ฐฑ์‹ ํ•˜๊ณ  ์œ„์น˜๋ฅผ ์นด์šดํŠธํ•œ๋‹ค (for ๊ตฌ๋ฌธ ๋‚ด์—์„œ 8๊นŒ์ง€ ๋Œ๋ฆฌ๋‹ˆ๊นŒ)

using System;
    using System.Text;

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                StringBuilder sb = new StringBuilder();
                int[] arr = new int[9];
                int max = arr[0];
                int count = 0;
                for (int i = 0; i < 9; i++)
                {
                    arr[i] = Convert.ToInt32(Console.ReadLine());
                    if (max < arr[i])
                    {
                        max = arr[i];
                        count++;
                    }
                }
                Array.Sort(arr);
                Console.WriteLine(arr[8] + "\\n" + count);
            }
        
        }

    }

๋Œ“๊ธ€