티스토리 뷰

문제 링크

https://www.acmicpc.net/problem/10992

 

10992번: 별 찍기 - 17

예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.

www.acmicpc.net

 

구현 코드

 

#include <iostream>
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;
int main(){
fastio;
int n;
cin >> n;
for(int i=0;i<n-1;i++){
for(int j=i;j<n-1;j++){
cout << ' ';
}
cout << '*';
if(i==0){
cout << endl;
continue;
}
for(int k=0;k<i*2-1;k++){
cout << ' ';
}
cout << '*' << endl;
}
for(int i=0;i<n*2-1;i++){
cout << '*';
}
cout << endl;
return 0;
}
view raw 10992.cpp hosted with ❤ by GitHub
n = int(input())
for i in range(n-1):
print(' ' * (n-i-1), end='')
print('*', end='')
if i==0:
print()
continue
print(' ' * (i*2-1), end='')
print('*')
print('*'*(n*2-1))
view raw 10992.py hosted with ❤ by GitHub