자라는 개발자/문제풀이
백준 c++ 20920 영단어 암기는 괴로워
자란다
2022. 7. 4. 14:45
728x90
반응형
20920 영단어 암기는 괴로워
문제풀이
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool cmp(pair<string, int> &a, pair<string, int> &b)
{
if (a.second==b.second)
{
if (a.first.length()==b.first.length())
return a.first < b.first;
return a.first.length() > b.first.length();
}
return a.second > b.second;
}
int n, m;
unordered_map<string, int> v;
int main(void)
{
fast_io();
cin >> n >> m;
for (int i = 0; i < n; i++)
{
string str;
cin >> str;
if (str.length() >= m)
v[str]++;
}
vector<pair<string, int>> vec(v.begin(), v.end());
sort(vec.begin(), vec.end(),cmp);
for (auto p : vec)
cout << p.first << "\n";
}
- 단어가 나온 빈도
- 단어의 길이
- 알파벳순으로 정렬했다.
728x90
반응형