프로그래머스 알고리즘/코딩 테스트 문제
C# 프로그래머스 [Level 1] _모의 고사
재호우96
2020. 5. 29. 18:56
반응형
C# 프로그래머스 [Level 1] _문제이름

출제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42840
코딩테스트 연습 - 모의고사
수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 ��
programmers.co.kr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class Solution | |
{ | |
public int[] solution(int[] answers) | |
{ | |
int[] s1 = new int[] { 1, 2, 3, 4, 5 }; // 5번 | |
int[] s2 = new int[] { 2, 1, 2, 3, 2, 4, 2, 5 }; // 8번 | |
int[] s3 = new int[] { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }; // 10번 | |
int[] count = new int[3]; // 맞은 정답 수 | |
int max = 0; // 정답 수의 max값 | |
List<int> nlist = new List<int>(); | |
// 같은 지 비교해서 count에 정답수를 올려줌 | |
for (int i = 0; i < answers.Length; i++) | |
{ | |
if (s1[i % 5] == answers[i]) { count[0]++; } | |
if (s2[i % 8] == answers[i]) { count[1]++; } | |
if (s3[i % 10] == answers[i]) { count[2]++; } | |
} | |
// 정답 배열의 제일 큰 값을 찾음 | |
for (int i = 0; i < 3; i++) | |
{ | |
if (max < count[i]) | |
{ | |
max = count[i]; | |
} | |
} | |
for (int i = 0; i < 3; i++) | |
{ | |
if (max == count[i]) | |
{ | |
nlist.Add(i + 1); | |
} | |
} | |
return nlist.ToArray(); | |
} | |
} |
반응형