Notice
Recent Posts
Recent Comments
Link
ยซ   2024/09   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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

[๋ฐฑ์ค€ 14612๋ฒˆ] ๊น€์‹๋‹น - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 14612๋ฒˆ] ๊น€์‹๋‹น - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 5. 5. 02:01
728x90
๋ฐ˜์‘ํ˜•

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

 

14612๋ฒˆ: ๊น€์‹๋‹น

์ธํ•˜๋Œ€ํ•™๊ต ์ถ•์ œ๋ฅผ ๋งž์ดํ•˜์—ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋™์•„๋ฆฌ CTP์—์„œ๋Š” ์‹๋‹น์„ ์—ด๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ์š”๋ฆฌ๋Š” ์„ธ์ง„์ด๊ฐ€ ํ•˜๊ฒŒ ๋˜์—ˆ๊ณ , ์ฃผ๋ฌธ์„ ๋ฐ›๋Š” ๊ฒƒ์€ ํ•œ์†”์ด๊ฐ€ ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ์‹๋‹น์˜ ์Œ์‹์ด ๋„ˆ๋ฌด ๋ง›์žˆ์–ด์„œ ์ฃผ๋ฌธ์€ ๋Š

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.push(line);
  if (input.length === +input[0].split(' ')[0] + 1) {
    rl.close();
  }
}).on('close', function () {
  const [N, M] = input.shift().split(' ').map(Number);
  const commands = input.map((v) => v.split(' '));
  const answer = [];
  const result = [];
  commands.forEach((ele) => {
    if (ele[0] === 'order') {
      result.push([ele[1], ele[2]].map(Number));
      answer.push(result.map((v) => v[0]));
    } else if (ele[0] === 'sort') {
      if (result.length === 0) {
        answer.push('sleep');
      } else {
        result.sort((a, b) => {
          if (a[1] === b[1]) {
            return a[0] - b[0];
          } else {
            return a[1] - b[1];
          }
        });
        answer.push(result.map((v) => v[0]));
      }
    } else {
      const resultFilterArr = result.map((v) => v[0]);

      if (resultFilterArr.includes(+ele[1])) {
        const idx = resultFilterArr.indexOf(+ele[1]);
        result.splice(idx, 1);
      }

      if (result.length > 0) {
        answer.push(result.map((v) => v[0]));
      } else {
        answer.push('sleep');
      }
    }
  });
  console.log(answer.map((v) => (Array.isArray(v) ? v.join(' ') : v)).join('\n'));
});

์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์€ sort์ฒ˜๋ฆฌ์ด๋‹ค. ์•„๋งˆ ๊ทธ๊ฒƒ ๋•Œ๋ฌธ์— ์ •๋‹ต๋ฅ ์ด ๋‚ฎ์€ ๊ฒƒ ๊ฐ™๋‹ค.

๋นˆ ๋ฐฐ์—ด์—์„œ sort ํ‚ค์›Œ๋“œ๊ฐ€ ์ง„ํ–‰๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ sleep์„ ์ถœ๋ ฅํ•ด์•ผํ•œ๋‹ค!

 

๋˜ํ•œ, sort๋ฅผ ์“ธ ๋•Œ ์ฃผ๋ฌธ ์‹œ๊ฐ„์ด ๊ฐ™์œผ๋ฉด ํ…Œ์ด๋ธ” ๋ฒˆํ˜ธ๊ฐ€ ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ๋„ ๊ณ ๋ คํ•ด์•ผํ•œ๋‹ค.

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