1. 오늘의 알고리즘 코드 카타 - 신고 결과 받기
답안 :
//신고가 중복되지 않도록 처리 => 신고 기록 저장해서 Contains 등 메서드 이용
//신고 당한 유저<Key>의 신고 유저 목록<List>을 알면 중복 메일도 신고 당한 유저 Key의 리스트에서 신고한 유저의 신고 횟수를 1회 늘리는 방식
//신고 당한 유저를 Key, 신고한 유저 목록을 List 형식의 Value로 딕셔너리
//Split()을 통해 report에 존재하는 값 중 신고한 유저를 give, 당한 유저를 tale
//신고 당한 유저가 딕셔너리에 Key로 존재하지 않으면 새로 생성
//존재할 경우 딕셔너리[take]로 신고한 유저 목록을 가져와서 이미 신고한 유저의 이름이 포함되어 있는지 비교 처리
//id_list에서 해당 리스트의 카운트가 신고 커트라인인 k보다 높거나 같은지 확인
using System;
using System.Collections;
using System.Collections.Generic;
public class Solution
{
public int[] solution(string[] id_list, string[] report, int k)
{
int[] answer = new int[id_list.Length];
Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
for (int i = 0; i < report.Length; i++)
{
string[] str = report[i].Split(' ');
string give = str[0];
string take = str[1];
if (!dic.ContainsKey(take))
{
List<string> list = new List<string>();
list.Add(give);
dic.Add(take, list);
continue;
}
if (!dic[take].Contains(give))
{
dic[take].Add(give);
}
}
for (int i = 0; i < id_list.Length; i++)
{
foreach (KeyValuePair<string, List<string>> item in dic)
{
if (item.Value.Contains(id_list[i]))
{
if (item.Value.Count >= k)
{
answer[i] = ++answer[i];
}
}
}
}
return answer;
}
}
2. 오늘의 작업
또 여러가지 브로셔 자료를 만들게 되었다.
그 부분을 담고 오늘도 빠르게 정리하고자 한다.
'TIL' 카테고리의 다른 글
[TIL]2024-4-26 / 79일차 - 최종 프로젝트 8주차 5일차 (0) | 2024.04.26 |
---|---|
[TIL]2024-4-25 / 78일차 - 최종 프로젝트 8주차 4일차 (1) | 2024.04.26 |
[TIL]2024-4-23 / 76일차 - 최종 프로젝트 8주차 2일차 (0) | 2024.04.24 |
[TIL]2024-4-22 / 75일차 - 최종 프로젝트 8주차 1일차 (1) | 2024.04.22 |
[TIL]2024-4-19 / 74일차 - 최종 프로젝트 7주차 5일차 (0) | 2024.04.20 |