문제

어떤 단어를 뒤에서부터 읽어도 똑같다면 그 단어를 팰린드롬이라고 한다. 'radar', 'sees'는 팰린드롬이다.

수도 팰린드롬으로 취급할 수 있다. 수의 숫자들을 뒤에서부터 읽어도 같다면 그 수는 팰린드롬수다. 121, 12421 등은 팰린드롬수다. 123, 1231은 뒤에서부터 읽으면 다르므로 팰린드롬수가 아니다. 또한 10도 팰린드롬수가 아닌데, 앞에 무의미한 0이 올 수 있다면 010이 되어 팰린드롬수로 취급할 수도 있지만, 특별히 이번 문제에서는 무의미한 0이 앞에 올 수 없다고 하자.

 

입출력 예시

 

해결

const fs = require('fs');
const { start } = require('repl');
const stdin = (process.platform === 'linux'
    ? fs.readFileSync('/dev/stdin').toString()
    : `121
1231
12421
0` 
).match(/[^\r\n]+/g);

let s = stdin
let i = 0;
let answer = []
while (true) {
  if (Number(s[i]) === 0) {
    break;
  }
  const v = s[i].split('')
  let result = 'yes'
  for (let j=0; j < Math.floor(v.length/2); j++ ){

    if (v[j] != v[v.length-1-j]){
      result = 'no'
      break;
    }
  }
  answer.push(result)
  i++;
}
console.log(answer.join('\n'))

'개발 공부 > Algorithm' 카테고리의 다른 글

[백준/Node.js] 팬그램  (0) 2023.03.20
[백준/Node.js] 탄산 음료  (0) 2023.03.17
[백준/Node.js] 약수  (0) 2023.03.15
[백준/Node.js] 최대공약수와 최소공배수  (0) 2023.03.14
[백준/node.js] 그릇  (0) 2023.03.11

+ Recent posts