[백준-node.js-26069] 붙임성 좋은 총총이

이태헌·2023년 6월 13일
0
post-thumbnail

문제

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

풀이

let input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n')
input.shift();
const dancers = new Set(); 

  for(let i = 0; i<input.length; i++){
    const [A,B] = input[i].split(' ') //1
    if(A === 'ChongChong' || B ==='ChongChong' || dancers.has(A)||dancers.has(B)){
      dancers.add(A)
      dancers.add(B)
    }
  }
  console.log(dancers.size)
  1. [A,B]형식으로 배열을 나눠준다
  2. A,B값중에 ChongChong이라는 사람이 있으면 setA,B 둘 다 넣어주고 set안에 한 사람이라도 있는 경우에 추가해준다.
  3. setsize출력

0개의 댓글