HackerRank/Algorithm
[HackerRank/Algorithms] Warmup - Staircase
개발자_조이킴
2022. 9. 3. 00:34
Problem. Warmup - Staircase
Link.
https://www.hackerrank.com/challenges/staircase/problem?isFullScreen=true
Staircase | HackerRank
Print a right-aligned staircase with n steps.
www.hackerrank.com
Description.
Key Point.
My Answer.
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'staircase' function below.
*
* The function accepts INTEGER n as parameter.
*/
function staircase(n) {
// Write your code here
let blank = ' '
let stair = '#'
for(let i = 1; i <= n; i++) {
console.log(blank.repeat(n - i) + stair.repeat(i));
}
}
function main() {
const n = parseInt(readLine().trim(), 10);
staircase(n);
}
References.