C# - 신고 결과 받기

2023. 3. 23. 00:47·프로그래머스

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
'프로그래머스' 카테고리의 다른 글
  • C# - 택배 배달과 수거하기
  • C# - 성격 유형 검사
  • C++ - 더 맵게
  • C# - 타겟 넘버
ybbro
ybbro
대부분의 포스팅은 pc에서 작성되었습니다. 모바일에서 볼 때 설명이 잘리면 데스크탑 모드를 사용해보길 바랍니다.
  • ybbro
    어떻게든 굴리는 게임 공방
    ybbro
  • 전체
    오늘
    어제
    • 전체 N
      • 스파르타코딩클럽_Unity개발과정 N
      • Unity 2D
        • 카드게임
        • 플랫포머 게임
        • 뱀서라이크
      • Unity 3D
        • 닷지
        • 유니티 짱
        • 디펜스 게임
      • Unity 에러 노트
      • 기능 구현 방법 정리
      • 셰이더 그래프
        • 2D
        • 3D
      • 프로그래머스
      • 자료구조
      • 기타
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    텍스트매시프로
    UI
    앱이 휴대전화와 호환되지 않아 설치되지 않았습니다
    룰렛
    세이브
    hello
    유니티 애니메이터 파라미터 초기화
    64비트
    다크모드
    무료스킨
    마스크
    unity
    잔상
    삭제
    직렬화
    sprite mask
    스파인
    갤럭시 S24
    대시
    유니티
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
ybbro
C# - 신고 결과 받기
상단으로

티스토리툴바