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

[백준 3022/javascript] PRASE

by tokkiC 2022. 9. 27.

미번역 문제.

입력한 아이의 쿠키를 +1 해주고

+1 해준 보유 숫자가 다른 아이들이 가진 쿠키의 총 합 + 1 보다 크다면 카운트 하여

출력해주면 되는 문제이다

사실상 영어 문제...

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

 

3022번: PRASE

The first line of input contains an integer N (1 ≤ N ≤ 100), how many pieces of food the children take.  Each of the following N lines contains the name of a child that took one piece of food. The names will be strings of at most 20 lowercase letters

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) => {
  let n = Number(inp.shift());
  let oj = {};
  let cnt = 0;

  for (let i = 0; i < inp.length; i++) {
    if (oj[inp[i]] === undefined) {
      oj[inp[i]] = 1;
    } else {
      oj[inp[i]]++;
      let others = 0;
      for (el in oj) {
        if (el !== inp[i]) {
          others += oj[el];
        }
      }
      if (oj[inp[i]] > others + 1) {
        cnt++;
      }
    }
  }
  console.log(cnt);
};

댓글