-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_명예의전당.cpp
59 lines (49 loc) · 1.24 KB
/
pg_명예의전당.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(int k, vector<int> score)
{
vector<int> answer;
vector<int> temp;
for (int i = 0; i < score.size(); i++)
{
if (i == 0)
{
answer.push_back(score[i]);
temp.push_back(score[i]);
continue;
}
else if (temp.size() < k)
{
temp.push_back(score[i]);
sort(temp.rbegin(), temp.rend());
answer.push_back(temp[temp.size() - 1]);
}
else
{
temp.push_back(score[i]);
sort(temp.rbegin(), temp.rend());
temp.erase(temp.end() - 1);
answer.push_back(temp[temp.size() - 1]);
}
}
return answer;
}
/**
* 다른 사람의 짧은 풀이
*/
// #include <string>
// #include <vector>
// #include <algorithm>
// using namespace std;
// vector<int> solution(int k, vector<int> score) {
// vector<int> answer, tmp;
// for(auto s : score){
// tmp.push_back(s);
// sort(tmp.begin(), tmp.end(), greater<int>());
// if(tmp.size() > k) tmp.erase(tmp.begin() + k, tmp.end());
// answer.push_back(tmp.back());
// }
// return answer;
// }