※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26510번 문제인 V for Vendetta이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26510
26510번: V for Vendetta
In the 2006 Wachowski Brothers movie thriller, starring Hugo Weaving as the main character and Natalie Portman as Evey, V is an anarchist freedom fighter who attempts to ignite a revolution against the brutal neo-fascist regime that has subjugated the dyst
www.acmicpc.net
각 테스트케이스마다 N을 입력받아 주어진 것과 같은 모양의 'V'자 모양의 별을 출력하는 문제이다.
규칙을 잘 살펴 반복문을 이용해 도형을 출력하고 문제를 해결하자.
각 행의 끝부분에 불필요한 개행을 출력하면 안됨에 유의하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int N;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while (cin >> N) {
for (int i = 0; i + 1 < N; i++) {
for (int j = 0; j < i; j++) cout << ' ';
cout << '*';
for (int j = 0; j < 2 * (N - i) - 3; j++) cout << ' ';
cout << '*' << '\n';
}
for (int i = 1; i < N; i++) cout << ' ';
cout << '*' << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26560 // C++] Period (0) | 2022.12.21 |
---|---|
[BOJ 26547 // C++] Square (0) | 2022.12.21 |
[BOJ 22421 // C++] Koto Municipal Subway (0) | 2022.12.21 |
[BOJ 26509 // C++] Triangle (0) | 2022.12.21 |
[BOJ 5356 // C++] Triangles (0) | 2022.12.21 |