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 struct User_Info
{
public int reported; // 신고당한 횟수
public List<int> reported_index; // 신고한 유저 인덱스
}
public int[] solution(string[] id_list, string[] report, int k)
{
// 중복된 신고 제거
string[] report_duplicate_removed = report.Distinct().ToArray();
int report_Length = report_duplicate_removed.Length;
// 정답 출력용으로 리스트 원소를 유저 수만큼 0으로 초기화
int id_list_Length = id_list.Length;
List<int> answer_List = new List<int>(id_list_Length);
answer_List.AddRange(Enumerable.Repeat(default(int), id_list_Length));
// 신고당한 횟수, 신고한 유저의 인덱스 초기화
User_Info[] user_infos = new User_Info[id_list_Length];
for (int i = 0; i < id_list_Length; i++)
{
user_infos[i].reported = 0;
user_infos[i].reported_index = new List<int>();
}
// 리포트의 갯수만큼
for (int i = 0; i < report_Length; i++)
{
// 리포트는 "신고자 신고대상자" 이 둘을 ' '으로 구분
string[] report_temp = report_duplicate_removed[i].Split(' ');
// 신고대상자와 같은 유저명을 찾으면 신고당한 횟수+1
int j = 0;
for (j = 0; j < id_list_Length; j++)
{
if(report_temp[1].Equals(id_list[j]))
{
user_infos[j].reported++;
break;
}
}
// 신고한 유저와 같은 유저명을 찾아 그 인덱스를 신고당한 유저의 정보에 추가
for (int n = 0; n < id_list_Length; n++)
{
if (report_temp[0].Equals(id_list[n]))
{
user_infos[j].reported_index.Add(n);
break;
}
}
}
// 모든 유저에 대해
for (int i = 0; i < id_list_Length; i++)
{
// 해당 유저가 신고당한 횟수가 기준치 이상이면,
if(user_infos[i].reported >= k)
// 신고한 유저들의 인덱스에 메일 보내는 횟수 +1
for (int j = 0; j < user_infos[i].reported_index.Count; j++)
{
answer_List[user_infos[i].reported_index[j]]++;
}
}
int[] answer = answer_List.ToArray();
return answer;
}
}
'프로그래머스' 카테고리의 다른 글
C# - 택배 배달과 수거하기 (0) | 2023.04.03 |
---|---|
C# - 성격 유형 검사 (0) | 2023.03.18 |
C++ - 더 맵게 (0) | 2023.03.09 |
C# - 타겟 넘버 (0) | 2023.03.02 |
C# - 조이스틱 (0) | 2023.02.28 |