티스토리 뷰

알고리즘/백준 문제풀이

백준 nodejs 7568번: 덩치

YG - 96년생 , 강아지 있음, 개발자 희망 2021. 10. 29. 10:57

 

 

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");

const testCount = +input[0]; //실행 횟수

for (let i = 1; i <= testCount; i++) {
  // 각각의 입력값 숫자의 배열을 만드는 과정
  input[i] = input[i].split(" ").map((item) => +item);
}

//console.log(input);

solution(input);

function solution(A) {
  for (let m = 1; m <= testCount; m++) {
    // 배열 1부터 textCount 배열까지 실행
    let ranking = 1; // 등수
    //console.log(A[m]);
    for (let k = 1; k <= testCount; k++) {
      // 각각의 덩치를 비교하기 위한 for문
      //console.log(A[k]);
      if (A[m][0] < A[k][0] && A[m][1] < A[k][1]) {
        // A[m][0] 과 나머지 값들을 비교하고 A[m][1] 과 나머지 값들을 전부 비교한다.
        ranking++; //두 값 모두 큰 다른 수가 있다면 등수를 +1 해준다
      }
    }
    console.log(ranking);
  }
}

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
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
글 보관함