티스토리 뷰


title: "별 찍기 - 2(2439)"
category: 백준[Class-1]
tags: [C++, JavaScript, 백준]
date: "2021-03-14"


문제 링크

별 찍기 - 2(2439)

C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// 문제 풀이 함수
void solution(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        string str1(n-i, ' ');
        string str2(i, '*');
        cout << str1+str2 << endl;
    }
}

bool exists(const char* fileName){
    FILE* fp;
    if((fp = fopen(fileName, "r"))){
        fclose(fp);
        return true;
    }
    return false;
}

int main() {
    if(exists("stdin")){
        freopen("stdin", "r", stdin);
        solution();
        fclose(stdin);
    }
    else{
        solution();
    }

    return 0;
}

JavsScript

const fs = require("fs");
// split 조절
const input = fs.readFileSync("dev/stdin").toString().trim().split(" ");

// 문제 풀이
const n = input[0];

for (let i = 1; i <= n; i++) {
  console.log(" ".repeat(n - i) + "*".repeat(i));
}
728x90
반응형

'Baekjoon Solutions > Class-1' 카테고리의 다른 글

[백준] 숫자의 개수(2577)  (0) 2021.03.14
[백준] 검증수(2475)  (0) 2021.03.14
[백준] 평균(1546)  (0) 2021.03.14
[백준] 단어 공부(1157)  (0) 2021.03.13
[백준] 단어의 개수(1152)  (0) 2021.03.13
댓글
05-02 09:29
링크