자라는 개발자/문제풀이

백준 c++ 20291 파일정리

자란다 2022. 6. 5. 21:42
728x90
반응형

20291 파일정리



문제풀이

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
map<string,int> ma;
int n;
vector<string> split(string str, char del){
    istringstream iss(str);
    string buf;
    vector<string> res;
    while(getline(iss,buf,del)){
        res.push_back(buf);
    }
    return res;
}
int main(void)
{
    fast_io();
    cin >> n;
    while(n--)
    {
        string str;
        cin >> str;
        vector<string> res = split(str, '.');
        ma[res[1]]++;
    }
    for (auto iter = ma.begin(); iter != ma.end();iter++)
        cout << iter->first<< " " << iter->second << "\n";
}

.을 기준으로 맵에 넣어준뒤 값을 출력했다.

728x90
반응형