프로그래머스 92334 신고 결과 받기

Jmnote (토론 | 기여)님의 2023년 12월 15일 (금) 00:56 판 (새 문서: ==개요== {{프로그래머스|레벨=1|페이지=2|분류=2022 KAKAO BLIND RECRUITMENT}} ==C++== <syntaxhighlight lang='cpp'> #include <iostream> #include <vector> #include <map> #...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

프로그래머스 92334 신고 결과 받기

2 C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

vector<int> solution(vector<string> id_list, vector<string> report, int k) {
    map<string,set<string>> userBads;
    for(string user: id_list) {
        userBads[user] = set<string>{};
    }
    for(string r: report) {
        int idx=0;
        while(r[idx] != ' ') idx++;
        string user = r.substr(0,idx);
        string bad = r.substr(idx+1);
        userBads[user].insert(bad);
    }
    map<string,int> badCount;
    for(auto& ub: userBads) {
        for(auto& bad: ub.second) {
            badCount[bad]++;
        }
    }
    vector<string> banned;
    for(auto& it: badCount) {
        if(it.second >= k) banned.push_back(it.first);
    }
    vector<int> result;
    for(string user: id_list) {
        int mail = 0;
        for(auto& bad: userBads[user]) {
            if(find(banned.begin(), banned.end(), bad) != banned.end()) {
                mail++;
            }
        }
        result.push_back(mail);
    }
    return result;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}