BaekJoon[C#]

정렬 단계 25305

wny0320 2022. 12. 26. 18:20

백준 온라인 코딩 문제풀이

https://www.acmicpc.net/

 

Baekjoon Online Judge

Baekjoon Online Judge 프로그래밍 문제를 풀고 온라인으로 채점받을 수 있는 곳입니다.

www.acmicpc.net

 

코드 참고

https://replit.com/@wny0320

 

wny0320 (박 상운)

Run code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.

replit.com

 

25305번에 대해 다룸

 


25305번

응시자 수와 등수가 정해지면 점수의 커트라인을 알려주는 코드를 작성하는 문제

 

이번에도 List의 Sort기능을 이용하였음

 

using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int[] score = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        List<int> scoreList = new List<int>(score);
        scoreList.Sort();
        scoreList.Reverse();
        Console.WriteLine(scoreList[input[1]-1]);
    }
}

input에 응시자의 수와 등수를 입력받아 Split하고 Array.ConvertAll로 전부 int 형태로 변환하여 배열을 선언

 

score도 마찬가지

 

score 배열을 List로 만든 scoreList 생성

 

scoreList를 오름차순 정렬 후 Reverse로 내림차순으로 배열을 뒤집음

 

여기서 index가 0부터 시작이기 때문에 input[1]에 해당하는 등수의 값 -1 을 하면 해당 등수의 점수가 나옴

'BaekJoon[C#]' 카테고리의 다른 글

백준 10988, 9506  (0) 2023.12.05
정렬 단계 2751  (0) 2022.12.27
정렬 단계 2587  (0) 2022.12.25
정렬 단계 2750  (0) 2022.12.24
2차원 배열 2563  (0) 2022.12.23