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

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/92334

#include <bits/stdc++.h>
using namespace std;

vector<string> split(string line) {
vector<string> v;
int point = 0;

for (int i = 0; i < line.size(); i++) {
if (line[i] == ' ') {
point = i;
break;
}
}

v.push_back(line.substr(0, point));
v.push_back(line.substr(point + 1));

return v;
}

vector<int> solution(vector<string> id_list, vector<string> report, int k) {
vector<int> answer = vector<int>(id_list.size(), 0);
map<string, set<string>> m;

for (string line : report) {
vector<string> v = split(line);
string id = v[0];
string report_id = v[1];

m[v[1]].insert(v[0]);
}

for (auto iter = m.begin(); iter != m.end(); iter++) {
if (iter->second.size() >= k) {
set<string>& s = iter->second;
for (auto s_iter = s.begin(); s_iter != s.end(); s_iter++) {
int index = find(id_list.begin(), id_list.end(), *s_iter) - id_list.begin();
answer[index]++;
}
}
}

return answer;
}
Share