I was shocked at the moment I saw the question. Because i had never seen the given codes before๐ฅฒ. Although i have just started studying IT things, I could not imagine that I was unable to understand what they want me to do with the given codes from the level 1 question๐คฃ.
Given description,
์ด ๋ฌธ์ ์๋ ํ์ค ์ ๋ ฅ์ผ๋ก ๋ ๊ฐ์ ์ ์ n๊ณผ m์ด ์ฃผ์ด์ง๋๋ค.
(๋ณ : * ) ๋ฌธ์๋ฅผ ์ด์ฉํด ๊ฐ๋ก์ ๊ธธ์ด๊ฐ n, ์ธ๋ก์ ๊ธธ์ด๊ฐ m์ธ ์ง์ฌ๊ฐํ ํํ๋ฅผ ์ถ๋ ฅํด๋ณด์ธ์.
Given condition,
์ ํ ์กฐ๊ฑด
n๊ณผ m์ ๊ฐ๊ฐ 1000 ์ดํ์ธ ์์ฐ์์ ๋๋ค.
// Given code
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
const n = data.split(" ");
const a = Number(n[0]), b = Number(n[1]);
console.log(a);
console.log(b);
});
So I had to figure out what "process", "stdin" and "setEncoding" mean.
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => //
// it looks excuting the code : standard input & output based on my research!
// once the code gets 'data', it goes through the function on the next
// it is separated in to two numbers.
const n = data.split(" ");
const a = Number(n[0]), b = Number(n[1]);
// the first letter (index 0) goes to variable 'a'
// the second letter (index 1) goes to variable 'b'
// and, it excutes rest of codes.
// ์
๋ ซ๋ฐ์ ์ ๋ณด 'data' ๋ฅผ n ์ด๋ผ๋ ๋ณ์์ ๋ฐ๊ณ split, -> ๋ฐฐ์ดํ
// n ๋ฐฐ์ด์์ ์ธ๋ฑ์ค 0์ ์๋ ์ ๋ณด๋ฅผ ์ซ์๋ก ๋ง๋ค๊ณ ๋ณ์ a ์ ํ ๋น
// ๊ฐ์ ๋ฐฉ์์ผ๋ก ๋ฐฐ์ด ์ธ๋ฑ์ค 1์ ์๋ ์ ๋ณด๋ฅผ ๋ณ์ b ์ํ ๋น
// ํ์ฉ์ค๋น ๋
process.stdin.setEncoding("utf8");
process.stdin.on("data", (data) => {
const n = data.split(" ");
const a = Number(n[0]),
b = Number(n[1]);
let star = function (a, b) {
for (let i = 0; i < m; i++) {
if (i < m) {
for (let k = 0; k < n; k++) {
console.log("*");
}
}
}
};
});
์ ์ถ๋ ฅ์ด ... ์๋์๋๊ฐ...
๊ตณ์ด ํจ์๋ก ์ ์ํด์ ํ ํ์๊ฐ ์์๊ณ ํจ์๋ ํธ์ถ์์ด ๋ฐ๋ก ์์ด์ผ ํ๋๋ฐ ์๋ง ๊ทธ๋ฐ๊ฑด ์๋์ ธ์ฃผ๋๋ฏ
process.stdin.setEncoding("utf8");
process.stdin.on("data", (data) => {
const n = data.split(" ");
const a = Number(n[0]),
b = Number(n[1]);
for (let i = 0; i < b; i++) {
star = "";
for (let k = 0; k < a; k++) {
star += "*";
}
console.log(star);
}
});
์ด๋ ๊ฒ ํ๋๊น ํต๊ณผ ๋์๋ค... ํ๋ก๊ทธ๋๋จธ์ค๊ฐ ์ด๋ป๊ฒ ๊ฐ์ ๋ฃ์ด์ฃผ๋์ง ์ดํด๋ฅผ ํด์ผํ ํ์๊ฐ ์์ ๋ฏ
ํผ์ ํ ๋ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ง ๊ทธ๋๋ก ๋ด๊ฐ ๋ค ํต์ ํ๋๋ฐ ์ฝ๋ฉ์ด๋ผ๋๊ฒ ๊ฒฐ๊ตญ ์ํธ์์ฉ์ ์ํ ์ธ์ด์ด๋๊น
๋ค๋ฅธ์ฌ๋๋ค์ ์ด๋ป๊ฒ?
How do other people do ?
process.stdin.setEncoding("utf8");
process.stdin.on("data", (data) => {
const n = data.split(" ");
const a = Number(n[0]),
b = Number(n[1]);
const row = "*".repeat(a);
for (let i = 0; i < b; i++) {
console.log(row);
}
});
// they used "repeat" to make the rows
// ๋ณ์ a๋ฒ ์ฐ๋ ์์
์ "row"์ ํ ๋นํด์
// column ์ b ๋งํผ ๋ฐ๋ณตํด์ ๋ง๋ค๋๋ง๋ค "row"๋ณ์๋ฅผ ํธ์ถ
// console.log ์๋ ์๋์ผ๋ก ์ค๋ฐ๊ฟํ๋๊ฒ ์์ด์
// ์ค๋ฐ๊ฟ์ด ๋ฐ๋ก ํ์ํ์ง ์์