https://www.acmicpc.net/problem/2562
2562번: 최댓값
9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어
www.acmicpc.net
List의 메서드를 사용하여 쉽게 풀 수 있다.
using System;
namespace _2562
{
class Program
{
static void Main()
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
List<int> ints = new List<int>();
for(int i = 0; i < 9; i++)
{
ints.Add(int.Parse(sr.ReadLine()));
}
int max = ints.Max();
int index = ints.FindIndex(x => x == max) + 1;
Console.WriteLine(max);
Console.WriteLine(index);
sr.Close();
}
}
}
'알고리즘 > 백준 BOJ' 카테고리의 다른 글
[ BOJ/C# ] 2920 음계 (0) | 2023.08.21 |
---|---|
[ BOJ/C# ] 3052 나머지 (0) | 2023.08.21 |
[ BOJ/C# ] 1157 단어 공부 (1) | 2023.08.20 |
[ BOJ/C# ] 1550 16진수 (0) | 2023.08.20 |
[ BOJ/C# ] 1330 두 수 비교하기 (0) | 2023.08.20 |