C#/알고리즘
백준#11004 - K번째 수
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;
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));
Console.WriteLine(intList[k - 1]);
}
}
}
|
리스트로 받아 정렬후 출력했습니다.