티스토리 뷰

package programmers;

class LottoLevel1 {
    public int printRank(int sol) {
        int rank = 0;
        switch(sol) {
            case 2:
                rank = 5;
                break;
            case 3:
                rank = 4;
                break;
            case 4:
                rank = 3;
                break;
            case 5:
                rank = 2;
                break;
            case 6:
                rank = 1;
                break;
            default:
                rank = 6;
                break;
        }
        return rank;
    }

    public int[] checkLotto(int[] lottos, int[] win_nums) {
        int sol[] = new int[2];
        int zeroCount = 0;
        int correctCount = 0;

        for(int i=0; i<lottos.length; i++) {
            if(lottos[i] == 0) {
                zeroCount++;
                continue;
            }
            for(int solve : win_nums) {
                if(lottos[i] == solve) {
                    correctCount++;
                }
            }
        }
        sol[0] = zeroCount;
        sol[1] = correctCount;
        return sol;
    }

    public int[] solution(int[] lottos, int[] win_nums) {
        int[] answer = new int[2];
        int[] result = new int[2];
        result = checkLotto(lottos,win_nums);
        int minRank = printRank(result[1] + result[0]);
        int maxRank = printRank(result[1]);
        answer[0] = minRank;
        answer[1] = maxRank;
        return answer;
    }
}
  • printRank() : 로또 순위를 리턴해주는 함수
  • checkLotto() : 0의 갯수, 로또 번호랑 일치하는 갯수를 리턴해주는 함수
  • solution() : 최소와 최대 순위를 리턴해주는 함수
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함