728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/77484
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
using System;
public class Solution {
public int[] solution(int[] lottos, int[] win_nums) {
Array.Sort(lottos); Array.Sort(win_nums);
int[] answer = new int[2];
int hit = 7, zero = 0;
for (int i = -1; ++i < win_nums.Length;)
{
if (lottos[i] == 0) ++zero;
for (int j = -1; ++j < lottos.Length;)
if (win_nums[i] == lottos[j])
{
--hit;
break;
}
}
if (hit == 7) hit = 6;
if (hit - zero < 1)
{
answer[0] = 1;
answer[1] = hit;
}
else
{
answer[0] = hit - zero;
answer[1] = hit;
}
return answer;
}
}
좀 더럽고 이상하고 요상하게 껄껄
반응형
'프로그래머스_C# > Level_1' 카테고리의 다른 글
[프로그래머스 C#] 6주차_복서 정렬하기 (0) | 2021.10.18 |
---|---|
[프로그래머스 C#] Level 1 Tips (0) | 2021.09.11 |
[프로그래머스 C#] 4주차 직업군 추천하기 (0) | 2021.09.10 |
[프로그래머스 C#] 숫자 문자열과 영단어 (0) | 2021.09.09 |
[프로그래머스 C#] 음양 더하기 (0) | 2021.09.09 |