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
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 21194 Meditation (0) | 2022.07.11 |
---|---|
백준 c++ 7795 먹을 것인가 먹힐 것인가 (0) | 2022.07.10 |
백준 c++ 1940 주몽 (0) | 2022.07.02 |
백준 c++ 17164 Rainbow Beads (0) | 2022.07.01 |
백준 c++ 12845 모두의 마블 (0) | 2022.06.26 |