[프로그래머스/C++]Lv.1 - 직사각형 별찍기

YH J·2023년 6월 8일
0

프로그래머스

목록 보기
123/168

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/12969

내 풀이

a,b입력받은거로 별찍음

내 코드

#include <iostream>

using namespace std;

int main(void) {
    int a;
    int b;
    cin >> a >> b;
    for(int i = 0; i < b; i++)
    {
        for(int j = 0; j < a; j++)
            cout << "*";
        cout<<"\n";
    }
    return 0;
}

다른 사람의 풀이

#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int a;
    int b;
    cin >> a >> b;

    string s;

    s.append(a, '*');

    for (int i = 0; i < b; ++i)
    {
        cout << s << endl;
    }
    return 0;
}

다른 사람의 풀이 해석

for문 횟수 줄일 수 있는듯

profile
게임 개발자 지망생

0개의 댓글