코딩테스트/프로그래머스

[1] 신고 결과 받기

ShovelingLife 2022. 5. 31. 15:50
vector<int> solution(vector<string> id_list, vector<string> report, int k) 
{
    vector<int> answer(id_list.size());
    unordered_map<string, set<string>> report_map;
    unordered_map<string, int> idx_map;
    stringstream ss;
 
    for (int i = 0; i < id_list.size(); ++i) 
         idx_map[id_list[i]] = i; 
 
    for (auto rep : report) 
    {
        ss.str(rep);
        string first, second; 
        ss >> first >> second;
        report_map[second].insert(first);
        ss.clear();
    }
    for (auto it : report_map) 
    { 
        if (it.second.size() >= k) 
        { 
            for (auto set_it : it.second) 
            { 
                int idx = idx_map[set_it];
                answer[idx]++; 
            }
        }
    }
    return answer;
}