반응형
https://programmers.co.kr/learn/courses/30/lessons/12969?language=javascript
문제설명
- 이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다. 별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요. |
제한 조건
|
문제 풀이
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
const n = data.split(" ");
const a = Number(n[0])
var b = Number(n[1]);
var txt = "";
while(b != 0){
txt = "";
for(var x = 0; x<a; x++){
txt += "*";
}
console.log(txt);
b -= 1;
}
});
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
const n = data.split(" ");
var a = Number(n[0]), b = Number(n[1]);
var txt = "";
while(a != 0){ // a-1; 을 따로 넣을 필요 없이 a-- > 0 대체가능
txt += "*";
a -= 1;
}
while(b != 0){
console.log(txt);
b -= 1;
}
});
다른 풀이
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++){ // for문 대신 row.repeat(b); 가능
console.log(row)
}
});
반응형
'기타 > 문제풀이' 카테고리의 다른 글
[JS] 행렬의 덧셈 (0) | 2022.03.29 |
---|---|
[js] 2016년 (0) | 2022.03.21 |
[프로그래머스_js]완주하지 못한 선수 (0) | 2021.04.17 |
댓글