코딩공부/프로그래머스

※[프로그래머스]Lv.1 신고 결과 받기 C#

usingsystem 2023. 6. 15. 09:50
728x90

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)
    {
        report = report.ToList().Distinct().ToArray();

        Dictionary<string, int> answer = new Dictionary<string, int>();
        Dictionary<string, int> reportCount = new Dictionary<string, int>();
        Dictionary<string, List<string>> reportInfo = new Dictionary<string, List<string>>();

        foreach (var key in id_list)
        {
            reportCount[key] = 0;
            reportInfo[key] = new List<string>();
            answer[key] = 0;
        }

        foreach (var item in report)
        {
            string[] split = item.Split(" ");
            reportCount[split[1]]++;
            reportInfo[split[0]].Add(split[1]);
        }

        foreach (var cKey in reportCount.Where(x => x.Value >= k))
        {
            foreach (var item in reportInfo)
            {
                if (item.Value.Contains(cKey.Key))
                {
                    answer[item.Key]++;
                }
            }
        }

        return answer.Values.ToArray();
    }
}
728x90