"*"의 높이와 너비를 1이라고 했을 때, "*"을 이용해 직각 이등변 삼각형을 그리려고합니다. 정수 n 이 주어지면 높이와 너비가 n 인 직각 이등변 삼각형을 출력하도록 코드를 작성해보세요.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
solution(Number(input[0]));
});
function solution(n) {
for(let i = 1; i < n + 1; i++) {
console.log('*'.repeat(i));
}
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
for (let i = 1; i <= +input[0]; i++) {
console.log('*'.repeat(i));
}
});
문제를 보자마자 초기화 코드 때문에 당황스러웠던 문제였다.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
console.log(Number(input[0]));
});
하지만 다른사람들의 풀이를 보니 초기화 코드는 잘못 작성되어있는게 아니라, 의도된 코드였다는 것을 알 수 있었다. 따라서 이 문제를 풀기 위해서는 초기화 코드를 이해하고 사용할 줄 알아야 풀 수 있는 문제라는 것을 알 수 있었다.
여태까지 내가 원하는 모양대로 함수만 만들면 되었던 경우와 다르게 주어진 조건(모듈)을 가지고 문제를 풀어야하는 문제도 있다는 것을 알 수 있었다.