Notice
Recent Posts
Recent Comments
Link
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 10610๋ฒˆ] 30 - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 10610๋ฒˆ] 30 - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 4. 5. 03:13
728x90
๋ฐ˜์‘ํ˜•

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

 

10610๋ฒˆ: 30

์–ด๋Š ๋‚ , ๋ฏธ๋ฅด์ฝ”๋Š” ์šฐ์—ฐํžˆ ๊ธธ๊ฑฐ๋ฆฌ์—์„œ ์–‘์ˆ˜ N์„ ๋ณด์•˜๋‹ค. ๋ฏธ๋ฅด์ฝ”๋Š” 30์ด๋ž€ ์ˆ˜๋ฅผ ์กด๊ฒฝํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ทธ๋Š” ๊ธธ๊ฑฐ๋ฆฌ์—์„œ ์ฐพ์€ ์ˆ˜์— ํฌํ•จ๋œ ์ˆซ์ž๋“ค์„ ์„ž์–ด 30์˜ ๋ฐฐ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์–ดํ•œ

www.acmicpc.net

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let input;
rl.on('line', function (line) {
  input = line.split('').map(Number);
  rl.close();
}).on('close', function () {
  console.log(solution(input));
});

function solution(num) {
  if (!num.includes(0)) {
    return -1;
  }
  if (num.reduce((acc, cur) => acc + cur, 0) % 3 !== 0) {
    return -1;
  }

  num = num.sort((a, b) => b - a);

  return num.join('');
}

30์˜ ๋ฐฐ์ˆ˜๊ฐ€ ๋˜๋Š” ์กฐ๊ฑด์€ ๋‘ ๊ฐ€์ง€์ด๋‹ค.

 

0์ด ์žˆ์–ด์•ผ ํ•˜๊ณ , ๊ฐ ์ž๋ฆฟ์ˆ˜๋ฅผ ๋”ํ•œ ๊ฐ’์ด 3์ด๋ž‘ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ ธ์•ผ ํ•œ๋‹ค.

 

์ด ๋‘ ๊ฐœ๋งŒ ์ฒ˜๋ฆฌํ•ด์ฃผ๋ฉด ์‰ฝ๊ฒŒ ๋‹ต์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ 10^5์ž๋ฆฌ ์ˆ˜๊นŒ์ง€ ์ฃผ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ์ถœ๋ ฅ ์ดˆ๊ณผ๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments