티스토리 뷰

 

const fs = require("fs");

const filePath = process.platform === "linux" ? "./input.txt" : "/dev/stdin"; //제 개발환경은 리눅스이기에 input.txt를 앞에 두었습니다.

// const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; // 실제 백준사이트에 제출할 때는 위에 filePath를 삭제하고 이 부분을 입력하면 됩니다.

let input = fs.readFileSync(filePath).toString().split("\n");

//console.log(input);

let lottos = input[0].split(",").map((item)=>+item)
let win_nums = input[1].split(",").map((item)=>+item)

//console.log(lottos,win_nums);

solution(lottos,win_nums);

function solution(lottos,win_nums) {
    let answer =[];
    let right =0;
    let zero =0;
    for(let i =0;i<lottos.length;i++){ // 나의 로또 번호와 당첨번호를 indexOf 로 비교하여 right 맞은 숫자를 구하고 , 0의 알아볼수 없는 숫자를 구하였습니다
        //console.log(win_nums.indexOf(lottos[i]))
        if(win_nums.indexOf(lottos[i]) !== -1){
            right++
        }
        if(lottos[i]===0){
            zero++
        }
    }
    answer.push(right+zero < 2 ? 6 : 7-(right+zero)) // right + zero 는 최대로 맞을 수 있는 개수이고 7-맞은 개수를 하면 당첨순위가 나오고 , 
    // 2개를 맞춰야 하므로 2개 이하인 것은 6등으로 표시하였습니다.
    answer.push(right <2 ? 6 : 7-right) // 위의 방법과 동일합니다
    //console.log(answer)
    return answer
    
}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함