알고리즘/백준 BOJ
[ BOJ/C# ] 2562 최댓값
왹져박사
2023. 8. 21. 22:11
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();
}
}
}
