#include <bits/stdc++.h>
using namespace std;
vector<int> solution(vector<string> id_list, vector<string> report, int k) {
vector<int> answer;
map<string, set<string>> reportList;
map<string, int> reportUser;
set<string> temp;
for(string id : id_list){
reportList.insert(pair<string, set<string>>(id, temp));
reportUser.insert(pair<string, int>(id, 0));
}
for(string s: report){
stringstream ss(s);
string x, y;
ss >> x >>y;
set<string> name = reportList.at(x);
name.insert(y);
reportList.erase(x);
reportList.insert(pair<string, set<string>>(x, name));
}
for(string name : id_list){
set<string> s = reportList.at(name);
for (auto it = s.begin(); it != s.end(); it++) {
int num = reportUser.at(*it);
reportUser.erase(*it);
reportUser.insert(pair<string,int>(*it, num+1));
}
}
for(string id : id_list){
int sum = 0;
set<string> s = reportList.at(id);
for (auto it = s.begin(); it != s.end(); it++) {
if(reportUser.at(*it)>=k){
sum++;
}
}
answer.push_back(sum);
}
return answer;
}
map에 값 삽입할 때 map.insert(pair<>()) 이용
map에는 중복 키 삽입 불가능하므로 값 바꾸려면 erase 후 insert!
stringstream으로 빈칸 제거
stringstream ss(s);
string x, y;
ss >> x >> y;
map, set 값 조회 - at(Key)
set 순회
set<string> s;
for (auto it = s.begin(); it != s.end(); it++) {
cout<< *it <<'\n';
}
오늘의 회고
- c++ 기본 문법을 ide 사용하지 않고도 자유롭게 쓸 수 있도록 연습 많이 하자.
- 내일(4/17) 학습 예정 : 스프링부트 온라인 강의 듣기
'algorithm > 문제 풀이' 카테고리의 다른 글
99클럽 코테 스터디 18일차 TIL - 백준 16953번 (A -> B) (0) | 2024.04.18 |
---|---|
99클럽 코테 스터디 17일차 TIL - 프로그래머스 전력망을 둘로 나누기 (0) | 2024.04.17 |
99클럽 코테 스터디 14일차 TIL - 프로그래머스 JadenCase 문자열 만들기 (0) | 2024.04.14 |
99클럽 코테 스터디 13일차 TIL - 백준 15654 (N과 M (5)) (0) | 2024.04.13 |
99클럽 코테 스터디 12일차 TIL - 프로그래머스 연속된 부분 수열의 합 (0) | 2024.04.12 |