출제 링크 : https://www.acmicpc.net/problem/2562
2562번: 최댓값
9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어
www.acmicpc.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Solution
{
class Program
{
static void Main(string[] args)
{
int lastIdx = 0; //몇 번째 수인지 알려줄 인덱스
int Cnt = 9;
int[] input_Num = new int[Cnt]; //입력한 숫자 담을 배열
int Max = int.MinValue;
for(int i=0; i<Cnt; i++)
{
input_Num[i] = int.Parse(Console.ReadLine());
if(input_Num[i] > Max)
{
Max = input_Num[i];
lastIdx = i;
}
}
Console.WriteLine($"{Max}\n{lastIdx+1}");
}
}
}
'Baekjoon 문제풀이' 카테고리의 다른 글
[Baekjoon 5단계(2)] 2577번 : 숫자의 개수 (0) | 2021.09.02 |
---|---|
[Baekjoon 5단계(1)] 10818번 : 최소, 최대 (0) | 2021.09.01 |
[Baekjoon 4단계(3)] 1110번 : 더하기 사이클 (0) | 2021.09.01 |
[Baekjoon 4단계(2)] 10951번 : A+B - 4 (0) | 2021.09.01 |
[Baekjoon 4단계(1)] 10952번 : A+B - 5 (0) | 2021.08.31 |