๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜/๋ฐฑ์ค€ JS

[๋ฐฑ์ค€] JS/ 14561 ํšŒ๋ฌธ

by Tamii 2021. 9. 27.
๋ฐ˜์‘ํ˜•

ํ˜„์‹ค์„ ๋ฐ›์•„๋“ค์—ฌ์•ผ ํ•œ๋‹ค. 

๋ฐ”๋กœ Node.js ๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์—ฐ์Šตํ•ด์•ผ ํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„!

 

๋‚ด ํ’€์ด (์ •๋‹ต)

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n').map((e) => e.split(' ').map(Number));;

input.shift();

const nArr = input.map((arr) => {
  const [num, n] = [arr[0], arr[1]];
  return num.toString(n);
});

const isPalindrome = (num) => {
  let lenNum = num.length;
  let hLenNum = Math.floor(num.length / 2);

  for (let i = 0; i < hLenNum; i++) {
    if (num[i] !== num[lenNum - i - 1]) return 0;
  }
  return 1;
};

nArr.map((n) => console.log(isPalindrome(n)));

๋ฐฐ์—ด๋กœ ์ž…๋ ฅ๋ฐ›์•„์„œ

ํ•˜๋‚˜์”ฉ ์ง„๋ฒ•์„ ๋ฐ”๊พผ ํ›„์—

isํ•จ์ˆ˜๋กœ ์ฒดํฌํ•˜๊ธฐ!

 

 

๋‹ค๋ฅธ ํ’€์ด

function solution(data) {
    const T = +data[0];

    let output = "";
    for (let i = 1; i <= T; i++) {
        const [A, n] = data[i];
        const str = BigInt(A).toString(n);
        output += str === str.split("").reverse().join("") ? "1\n" : "0\n";
    }

    return output;
}

์™€์šฐ..

๋‚˜์˜ ์ฝ”๋“œ์—์„œ 

๋งŒ๋“ค์–ด์ง„ n์ง„๋ฒ• ์ˆ˜๋ฅผ .reverse()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋น„๊ตํ•˜๋‹ค๋‹ˆ!! ์ƒ๊ฐ์น˜ ๋ชปํ–ˆ๋‹ค.

ํ•œ์ค„์ฝ”๋”ฉ์ธ๊ฐ€..

 

 

 

๋‹จ์ˆœํ•œ ๋ฌธ์ œ์ธ๋ฐ ์˜ค๋žœ๋งŒ์— ๋ฐฑ์ค€์œผ๋กœ JS๋ฅผ ํ’€๋ ค๋‹ˆ ์ต์ˆ™์น˜ ์•Š์•˜๋”ฐ.

๋Œ“๊ธ€