๋ฌธ์ œ

์–ด๋–ค ๋‹จ์–ด๋ฅผ ๋’ค์—์„œ๋ถ€ํ„ฐ ์ฝ์–ด๋„ ๋˜‘๊ฐ™๋‹ค๋ฉด ๊ทธ ๋‹จ์–ด๋ฅผ ํŒฐ๋ฆฐ๋“œ๋กฌ์ด๋ผ๊ณ  ํ•œ๋‹ค. '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'))

๋ฌธ์ œ

์–‘์ˆ˜ A๊ฐ€ N์˜ ์ง„์งœ ์•ฝ์ˆ˜๊ฐ€ ๋˜๋ ค๋ฉด, N์ด A์˜ ๋ฐฐ์ˆ˜์ด๊ณ , A๊ฐ€ 1๊ณผ N์ด ์•„๋‹ˆ์–ด์•ผ ํ•œ๋‹ค. ์–ด๋–ค ์ˆ˜ N์˜ ์ง„์งœ ์•ฝ์ˆ˜๊ฐ€ ๋ชจ๋‘ ์ฃผ์–ด์งˆ ๋•Œ, N์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

ํ•ด๊ฒฐ

const fs = require('fs');
const { start } = require('repl');
const stdin = (process.platform === 'linux'
    ? fs.readFileSync('/dev/stdin').toString()
    : `14
14 26456 2 28 13228 3307 7 23149 8 6614 46298 56 4 92596` 
).match(/[^\r\n]+/g);

const input = (() => {
  let line = 0;
  return () => stdin[line++];
})();

const s = Number(input())
const v = input().split(' ').map(Number).sort((a,b) => a-b)
const num = v[0] * v[v.length-1]
console.log(num)

๋ฌธ์ œ

๋‘ ๊ฐœ์˜ ์ž์—ฐ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์—๋Š” ๋‘ ๊ฐœ์˜ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด ๋‘˜์€ 10,000์ดํ•˜์˜ ์ž์—ฐ์ˆ˜์ด๋ฉฐ ์‚ฌ์ด์— ํ•œ ์นธ์˜ ๊ณต๋ฐฑ์ด ์ฃผ์–ด์ง„๋‹ค.

 

์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

ํ•ด๊ฒฐ

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

const input = (() => {
  let line = 0;
  return () => stdin[line++];
})();

const s = input().split(' ').map(Number)

const solution = (n,m) => {
  const gcd = (a,b) => {
    if (b === 0) return a;
    return gcd(b, a%b)
  }

  const lcm = (a,b) => a*b / gcd(a,b);

  console.log(gcd(n,m))
  console.log(lcm(n,m))
  return;
}

solution (s[0],s[1])

+ Recent posts