본문 바로가기
개발 노트/백준, 프로그래머스 풀이

[백준 9872/javascript] Record Keeping

by tokkiC 2022. 10. 3.

영어 미번역 문제.

소들의 이름 목록을 먼저 정렬하고, JON 문자열로 만들어서 키 값으로 객체 카운트하여

객체의 값을 배열로 받아 그 중 최대값을 출력하였다

https://www.acmicpc.net/problem/9872

 

9872번: Record Keeping

Farmer John has been keeping detailed records of his cows as they enter the barn for milking. Each hour, a group of 3 cows enters the barn, and Farmer John writes down their names. For example over a 5-hour period, he might write down the following list, w

www.acmicpc.net

let input = [];

const readline = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

readline.on("line", (line) => {
  input.push(line);
});

readline.on("close", () => {
  solution(input);
  process.exit();
});

const solution = (inp) => {
  inp.shift();
  let oj = {};
  for (el of inp) {
    let str = JSON.stringify(el.split(" ").sort());
    if (oj[str]) {
      oj[str]++;
    } else {
      oj[str] = 1;
    }
  }
  let ojvalue = Object.values(oj);
  let ans = Math.max(...ojvalue);

  console.log(ans);
};

댓글