슈뢰딩거의 고등어
[2022 Kakao blind recruitment] 신고 결과 받기 본문
https://programmers.co.kr/learn/courses/30/lessons/92334
[풀이방법]
1. 아이디에 따른 번호를 부여한다.
map <string, int> m 형식으로 저장한다. int 는 id_list 의 순서대로
2. 신고자와 신고된 유저의 관계를 arr 에 저장해준다.
신고자 a 신고된 유저 b 의 경우 arr[a][b] = true 로 나타내 준다.
bool 형식으로 저장한 이유는 각 유저들은 같은 유저를 여러번 신고할 수 있지만, 동일한 유저에 대한 신고횟수는 1회로 처리가 되기때문이다.
3. 각 유저마다 얼마나 신고가 되었는지 확인한다.
arr[0][b], arr[1][b], ... arr[마지막번호][b] 까지 true 인 갯수를 센다.
4. 신고된 횟수가 k 가 넘는지 확인한다.
5. k 번 이상 신고가 되었다면, 유저b를 신고한 유저들에게 메세지를 보낸다.
arr[a][b] 까지 true 인 a 유저들에 대한 Message 를 ++ 해준다.
[코드]
#include <string>
#include <vector>
#include <sstream>
#include <map>
using namespace std;
map <string, int> m;
bool arr[1000][1000];
vector <int> message;
void send_message(int target_no) {
for(int i=0; i<m.size(); i++) {
if(arr[i][target_no] == true) {
message[i]++;
}
}
}
vector<int> solution(vector<string> id_list, vector<string> report, int k) {
message.resize(id_list.size(), 0);
for(int i=0; i<id_list.size(); i++) {
string id = id_list[i];
m.insert(make_pair(id, i));
}
for(auto r : report) {
string s[2];
istringstream stt(r);
stt >> s[0] >> s[1];
int a = m[s[0]];
int b = m[s[1]];
arr[a][b] = true;
}
for(int col=0; col<id_list.size(); col++) {
int cnt = 0;
for(int row=0; row<id_list.size(); row++) {
if(arr[row][col] == true)
cnt++;
}
if(cnt >= k) {
send_message(col);
}
}
return message;
}
'알고리즘' 카테고리의 다른 글
[2021 Kakao blind recruitment] 메뉴 리뉴얼 (0) | 2022.03.23 |
---|---|
[2022 Kakao blind recruitment] 주차 요금 계산 (0) | 2022.03.23 |
[2022 Kakao blind recruitment] 양궁대회 (0) | 2022.03.22 |
[2021 Kakao blind recruitment] 순위검색 (0) | 2022.03.22 |
[백준] 1107 리모컨 (0) | 2022.03.20 |
Comments