본문 바로가기

Algorithm/BAEKJOON

[BOJ] 20291번 파일 정리 (C++)

728x90
반응형

https://www.acmicpc.net/problem/20291

 

20291번: 파일 정리

친구로부터 노트북을 중고로 산 스브러스는 노트북을 켜자마자 경악할 수밖에 없었다. 바탕화면에 온갖 파일들이 정리도 안 된 채 가득했기 때문이다. 그리고 화면의 구석에서 친구의 메시지를

www.acmicpc.net

 

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
	cin >> n;
	
	string str;
	map<string, int> m;
	
	for(int i = 0; i < n; i++){
		cin >> str;
		int idx = str.find('.');
		str = str.substr(idx + 1);
		if(m.find(str) != m.end()){
			m[str]++;
		} else {
			m[str] = 1;
		}
	}
	
	for(auto iter = m.begin(); iter != m.end(); iter++){
		cout << iter->first << " " << iter->second << endl;
	}

	return 0;
}
728x90
반응형