세 정수 중에서 두 번째로 큰 정수를 출력하는 프로그램을 작성하는 문제이다.
입력받은 값을 string 배열에 넣고, 다시 int 배열로 만들어
int 배열을 내림차순으로 정렬해 for문으로 반복했다.
반복문에서는 두번째로 큰 값만을 출력하도록 작성했다.
기초 단계 if문이라 이용해서 값을 비교하며 풀어야 할 것 같긴한데.. LINQ로 했다
using System;
using System.Linq;
public class MainClass {
public static void Main() {
string value = Console.ReadLine();
string[] strResult = value.Split(' ');
int[] result = new int[strResult.Length];
for (int i=0;i<strResult.Length;i++)
{
result[i] = Convert.ToInt32(strResult[i]);
}
result = result.OrderByDescending(c => c).ToArray();
for(int i=0;i<result.Length;i++)
{
if (i==1)
Console.WriteLine(result[i]);
}
}
}
|
cs |
'C#' 카테고리의 다른 글
[백준] 15552번 빠른 A+B 풀이 (0) | 2020.04.15 |
---|---|
[백준] 2884번 알람 시계 C# 풀이 (0) | 2019.09.24 |
[백준] 2753번 윤년 C# 풀이 (0) | 2019.09.24 |
[백준] 9498번 시험성적 C# 풀이 (0) | 2019.09.21 |
[백준] 1330번 두 수 비교하기 C# 풀이 (0) | 2019.09.21 |