본문 바로가기
개발/문제풀이

문제풀이)프로그래머스)2022 KAKAO BLIND RECRUITMENT -신고 결과 받기

by 테샤르 2022. 7. 19.

2022 KAKAO BLIND RECRUITMENT -신고 결과 받기

URL : https://school.programmers.co.kr/learn/courses/30/lessons/92334

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

<테스트 코드>

using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int[] solution(string[] id_list, string[] report, int k) {
int[] answer = new int[id_list.Length];
//int[] banCount = new int[id_list.Length];
ReportInfo[] reportArr = new ReportInfo[id_list.Length];
for (int i = 0; i < id_list.Length; i++)
{
reportArr[i] = new ReportInfo(id_list[i]);
}
for (int i = 0; i < report.Length; i++)
{
string [] token = report[i].Split(' ');
string fromUser = token[0];
ReportInfo info = reportArr[Array.IndexOf(id_list, fromUser)];
info.Insert(report[i]);
}
List<string> totalBanList = new List<string>(); //TotalBanList
for (int i = 0; i < reportArr.Length; i++)
{
totalBanList.AddRange(reportArr[i].GetToArr());
}
for (int i = 0; i < reportArr.Length; i++)
{
List<string> fromLIst = reportArr[i].GetToArr(); //신고한 친구들의 데이터를 기반으로 TotalBanList의 Count를 계산
for (int j = 0; j < fromLIst.Count; j++)
{
var count = totalBanList.Count(s => s.Contains(fromLIst[j]));
if (count < k)
continue;
answer[i]++;
}
}
return answer;
}
public class ReportInfo
{
private string id;
private List<string> arrList = null; //신고한
public ReportInfo(string _id)
{
id = _id;
arrList = new List<string>();
}
public void Insert(string _id)
{
if (arrList.Contains(_id))
return;
arrList.Add(_id);
}
public List<string> GetList()
{
return arrList;
}
private List<string> ToArrList(int _index)
{
List<string> returnValue = new List<string>();
for (int i = 0; i < arrList.Count; i++)
{
string[] token = arrList[i].Split(' ');
returnValue.Add(token[_index]);
}
return returnValue;
}
public List<string> GetFromArr()
{
return ToArrList(0);
}
public List<string> GetToArr()
{
return ToArrList(1);
}
}
}

 

< 문제 해석 >

 

신고를 k 번 받은 유저에 대해서는 신고처리를 진행한다.

report 는 "신고한 유저 신고당한유저" 에 대한 데이터이다.

id_list는 유저의 전체 리스트 이고 answer의 순서와 동일하다.

 

ReportInfo Class에 유저를 고유한 key로 report의 리스트를 중복처리해서 insert 진행하고

전체의 데이터를 다 처리한 이후에 모든 신고한 유저를 totalBanList로 통합한다.

ReportInfo Class 의 데이터만큼 반복해서 유저가 신고한 유저가 k번 이상 받았는 지 판단해서 '결과 메일 횟수'를 가산한다.

 

 ★☆☆☆☆

 

반응형

댓글