-
[20291] 파일 정리BOJ 2022. 2. 22. 17:13
https://www.acmicpc.net/problem/20291
20291번: 파일 정리
친구로부터 노트북을 중고로 산 스브러스는 노트북을 켜자마자 경악할 수밖에 없었다. 바탕화면에 온갖 파일들이 정리도 안 된 채 가득했기 때문이다. 그리고 화면의 구석에서 친구의 메시지를
www.acmicpc.net
파싱은 find('.')이 return한 iterator의 다음것부터 취해주면 된다.
입력에서 확장자를 파싱한 다음에, multiset에 하나를 넣고 set에 하나를 넣는다고 생각하자.
기본적인 구현은 multiset으로 충분하나, 출력조건을 맞춰주기 위해서 중복을 허용/비허용하는 자료구조를 동시에 썼다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;int n;multiset<string> st;vector<string> v;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;int i;for (i = 0; i < n; i++) {string s;cin >> s;auto idx = find(s.begin(), s.end(), '.');s = string(++idx, s.end());st.insert(s);v.push_back(s);}sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());int S = v.size();for (i = 0; i < S; i++) {string cur = v[i];cout << cur << ' ' << st.count(cur) << '\n';}return 0;}
'BOJ' 카테고리의 다른 글
[21554] 마법의 돌 장난감 (0) 2022.02.22 [2445] 별 찍기 - 8 (0) 2022.02.22 [10728] XOR삼형제 1 (0) 2022.02.21 [4991] 로봇 청소기 (0) 2022.02.21 [13911] 집 구하기 (0) 2022.02.20