상세 컨텐츠

본문 제목

백준#11004 - K번째 수

C#/알고리즘

by McRobbin 2020. 4. 20. 14:13

본문

https://www.acmicpc.net/problem/11004

 

11004번: K번째 수

수 N개 A1, A2, ..., AN이 주어진다. A를 오름차순 정렬했을 때, 앞에서부터 K번째 있는 수를 구하는 프로그램을 작성하시오.

www.acmicpc.net

정렬로 분류된 11004 - K번째 수 입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _11004
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
 
            int count = int.Parse(input[0]);
            int k = int.Parse(input[1]);
 
            var intList = new List<int>();
 
            string[] numInput = Console.ReadLine().Split(' ');
 
            foreach (string num in numInput)
                intList.Add(int.Parse(num));
 
            intList.Sort();
 
            Console.WriteLine(intList[k - 1]);
 
        }
    }
}
 
 
 

 

리스트로 받아 정렬후 출력했습니다.

'C# > 알고리즘' 카테고리의 다른 글

백준#3047 - ABC  (0) 2020.04.21
백준#10825 - 국영수  (0) 2020.04.21
백준#11651 - 좌표 정렬하기 2  (0) 2020.04.20
백준#10814 - 나이순 정렬  (0) 2020.04.20
백준#11650 - 좌표 정렬하기  (0) 2020.04.20

관련글 더보기