Study hard
(c++)백준 11004번: K번째 수 본문
https://www.acmicpc.net/problem/11004
11004번: K번째 수
수 N개 A1, A2, ..., AN이 주어진다. A를 오름차순 정렬했을 때, 앞에서부터 K번째 있는 수를 구하는 프로그램을 작성하시오.
www.acmicpc.net

[풀이]
C++ STL의 sort함수를 이용하여 정렬하고, K번째에 있는 수를 출력하면 된다.
#include <iostream>
#include <vector>
#include <algorithm>//sort
#include <cstdio>
using namespace std;
int N, K;
vector<int>A;
void input() {
	int n;
	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%d", &n);
		A.push_back(n);
	}
}
void solution() {
	input();
	sort(A.begin(), A.end());
	printf("%d\n", A[K - 1]);
}
int main() {
	solution();
	return 0;
}'백준 > 여러가지 문제들' 카테고리의 다른 글
| (c++)백준 9012번: 괄호 (0) | 2020.06.12 | 
|---|---|
| (c++)백준 10828번: 스택 (0) | 2020.06.11 | 
| (c++)백준 11652번: 카드 (0) | 2020.06.11 | 
| (c++)백준 10989번: 수 정렬하기 3 (0) | 2020.06.11 | 
| (c++)백준 10825번: 국영수 (0) | 2020.06.11 | 
 
                   
                   
                  