https://www.acmicpc.net/problem/20920
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool compare(pair<string, int> n1, pair<string, int> n2) {
if (n1.second == n2.second) {
if (n1.first.size() == n2.first.size()) {
return n1.first < n2.first;
}
else return (n1.first.size()) > (n2.first.size());
}
return n1.second > n2.second;
}
int main(void) {
CPP_INIT();
int input1, input2;
string str;
map<string, int> m;
cin >> input1 >> input2;
for (int i = 0; i < input1; i++) {
cin >> str;
if (str.size() < input2) continue;
m[str]++;
}
vector<pair<string, int>> v(m.begin(), m.end());
sort(v.begin(), v.end(), compare);
for (int i = 0; i < v.size(); i++) {
cout << v[i].first << endl;
}
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 10870 피보나치 수 5 (0) | 2025.01.17 |
---|---|
C++ 알고리즘 - 백준 11729 하노이 탑 이동순서 (재귀함수) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 26069 붙임성 좋은 총총이 (0) | 2025.01.16 |
C++ 알고리즘 - 백준 25192 인사성 밝은 곰곰이 (0) | 2025.01.16 |
C++ 알고리즘 - 백준 1037 약수 (0) | 2025.01.16 |