Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- BFS
- 알고리즘
- 자료구조
- 그리디 알고리즘
- 수학
- 백트래킹
- 재귀
- 다익스트라
- Team Fortress 2
- 정렬
- 그래프
- 유니온 파인드
- 우선순위 큐
- 구현
- ue5
- 누적 합
- 문자열
- 유니티
- 스택
- 다이나믹 프로그래밍
- DFS
- 트리
- XR Interaction Toolkit
- 브루트포스
- c++
- Unreal Engine 5
- 시뮬레이션
- 백준
- 투 포인터
- VR
Archives
- Today
- Total
1일1알
백준 20920번 영단어 암기는 괴로워 C++ 본문
https://www.acmicpc.net/problem/20920
20920번: 영단어 암기는 괴로워
첫째 줄에는 영어 지문에 나오는 단어의 개수 $N$과 외울 단어의 길이 기준이 되는 $M$이 공백으로 구분되어 주어진다. ($1 \leq N \leq 100\,000$, $1 \leq M \leq 10$) 둘째 줄부터 $N+1$번째 줄까지 외울 단
www.acmicpc.net
map을 통해서 각 단어가 몇번 나왔는지 기록하고 조건에 맞게 정렬하였다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
struct Info {
string str;
int cnt;
bool operator<(const Info& other) const {
if (cnt != other.cnt) return cnt > other.cnt;
else {
if (str.length() == other.str.length()) return str < other.str;
return str.length() > other.str.length();
}
}
};
map<string, int> m1;
vector<Info> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
if (str.length() < m) continue;
m1[str]++;
}
for (auto a : m1) {
v.push_back({ a.first,a.second });
}
sort(v.begin(), v.end());
for (auto a : v) {
cout << a.str << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 15558번 점프 게임 C++ (0) | 2022.12.25 |
---|---|
백준 19640번 화장실의 규칙 C++ (0) | 2022.12.24 |
백준 16924번 십자가 찾기 C++ (0) | 2022.12.22 |
백준 2072번 오목 C++ (0) | 2022.12.21 |
백준 23757번 아이들과 선물 상자 C++ (0) | 2022.12.20 |