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);
}
}
}
'๐ฉโ๐ปProgramming > Coding Test' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [C#] [BOJ#3052] ๋๋จธ์ง - ์ค๋ณต ์ ๊ฑฐ (0) | 2022.07.30 |
|---|---|
| [C#] [BOJ#2577] ์ซ์์ ๊ฐ์ (0) | 2022.07.30 |
| [C#] [BOJ#10871] X๋ณด๋ค ์์ ์ (0) | 2022.07.30 |
| [C#] [BOJ#11021] A+B - 7 / A+B - 8 (0) | 2022.07.30 |
| [C#] [BOJ#2741] String Builder - N ์ฐ๊ธฐ, ๊ธฐ์ฐ N (0) | 2022.07.30 |
๋๊ธ