728x90
map을 이용하면 쉽게 풀리는 구현문제이다.
string 입력에서 어떻게 해야할지만 안다면 바로 풀린다.
문자열 일부를 return하는 substr함수를 이용해서 '.' 다음 글자부터 끝까지 return받는다.
그렇게 받은 값을 맵에 저장한다. (default가 오름차순이므로)
#include <iostream>
#include <map>
using namespace std;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N; cin >> N;
map<string, int> m;
for(int i=0; i<N; i++) {
string t; cin >> t;
string extension = t.substr(t.find('.')+1);
m[extension]++;
}
for(auto x : m)
cout << x.first << " " << x.second << '\n';
return 0;
}
728x90
'Algorithm > 백준과 프로그래머스' 카테고리의 다른 글
[C++] 16926. 배열 돌리기1 (0) | 2024.03.11 |
---|---|
[C++] 16234. 인구이동 (0) | 2024.03.07 |
[C++] 17413. 단어 뒤집기2 (0) | 2024.03.06 |
[프로그래머스/C++] LV2. 기능개발 (0) | 2024.02.02 |
[프로그래머스] LV1. 키패드 누르기 (0) | 2024.01.19 |