๐ฉ๐ปโ๐ป๋ฌธ์ ๋งํฌ
[๋ฐฑ์ค 2816] ๋์งํธ ํฐ๋น (Javascript)
โ๏ธIdea Sketch
2021-07-19
1. KBS1, KBS2์ ์์น๋ฅผ ์์์ผ ํจ
2. KBS1์ ์์น๊ฐ 1์ด๋ผ๋ฉด, 1ํ๊ณ 4
3. 1๊ณผ 4๋ก๋ ์ถฉ๋ถํ ํ ์ ์์ง ์๋??
โ๏ธ์์ค์ฝ๋
2021-07-19 ํต๊ณผ, 112ms
let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split('\n');
let N = parseInt(input.shift());
let index1 = input.indexOf('KBS1');
let index2 = input.indexOf('KBS2');
index2 = index1>index2 ? ++index2 : index2;
let result = '';
for (let i=0; i<index1; i++) {
result += '1';
}
for (let i = 0; i < index1; i++) {
result += '4';
}
for (let i = 0; i < index2; i++) {
result += '1';
}
for (let i = 0; i < index2-1; i++) {
result += '4';
}
console.log(result)
๋ฐฑ์ค๊ณผ vscode์์ ๋ค๋ฅธ ์
- ๋ฐฑ์ค : split('\r\n') ์ฌ์ฉ ์ ํ๋ ธ์ต๋๋ค!
let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split('\n');
let count = input.shift();
- vscode : split('\n') ์ฌ์ฉ ์ ๋ฐฐ์ด ๋์ \r์ด ๋ถ์
- ex) [ 'KBS2\r', 'ABC02\r', 'KBS1\r', 'KBS5' ]
let fs = require('fs');
let input = fs.readFileSync('inputํ
์คํธํ์ผ๊ฒฝ๋ก').toString().split('\r\n');
let count = input.shift();