정렬한 후 K번째의 수를 출력하는 문제입니다.
sort함수로 정렬한 후 출력해주었습니다.
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
int n, m;
int num;
vector<int> v;
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < n; ++i) {
scanf("%d", &num);
v.push_back(num);
}
sort(v.begin(), v.end());
printf("%d\n", v[m - 1]);
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 3047번 ABC (0) | 2019.09.16 |
---|---|
[C++] 백준 10825번 국영수 (0) | 2019.09.16 |
[C++] 백준 3055번 탈출 (0) | 2019.09.13 |
[C++] 백준 2589번 보물섬 (0) | 2019.09.13 |
[C++] 백준 7562번 나이트의 이동 (0) | 2019.09.13 |