๐Ÿ’  Cpp/[Solved.ac] Random Marathon

[BOJ][C++] ๋ฐฑ์ค€ 10992๋ฒˆ: ๋ณ„ ์ฐ๊ธฐ - 17 (Bronze III)

์„ ๋‹ฌ 2025. 1. 21. 02:43
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

์˜ˆ์ œ๋ฅผ ๋ณด๊ณ  ๊ทœ์น™์„ ์œ ์ถ”ํ•œ ๋’ค์— ๋ณ„์„ ์ฐ์–ด ๋ณด์„ธ์š”.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N(1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

ํ’€์ด

// ํ’€์ด : https://whkakrkr.tistory.com

#include <iostream>
#include <vector>

using namespace std;

void print(string ch, int num) {
    for(int i=0; i<num; i++) {
        cout << ch;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	
	if(n==1) {
	    cout << "*";
	    return 0;
	}
	
	print(" ", n-1);
	cout << "*\n";
	for(int i=2; i<n; i++) {
	    print(" ", n-i);
	    cout << "*";
	    print(" ", i*2-3);
	    cout << "*\n";
	}
	print("*", 2*n-1);

    return 0;
}
๋ฐ˜์‘ํ˜•