※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 5356번 문제인 Triangles이다.
문제는 아래 링크를 확인하자.

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

 

5356번: Triangles

Read in a letter and a number. The number indicates how big the letter triangle should be. The number indicating the size of the triangle will have a range from 0 to 250 (i.e., num>=0 and num<=250). The letters must wrap around from Z to A. If you start wi

www.acmicpc.net

각 차례에 해당하는 알파벳을 각 차례에 맞는 개수씩 출력해 문제를 해결하자. 이는 반복문을 이용해 구현할 수 있다.

 

각 테스트케이스의 결과 사이에 빈 줄이 한 줄 더 삽입되어야  함에 유의하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int T, N;
char c;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T;
	while (T--) {
		cin >> N >> c;
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j < i; j++) cout << c;
			cout << '\n';
			c++;
			if (c > 'Z') c = 'A';
		}
		cout << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 22421 // C++] Koto Municipal Subway  (0) 2022.12.21
[BOJ 26509 // C++] Triangle  (0) 2022.12.21
[BOJ 26534 // C++] Goats  (0) 2022.12.21
[BOJ 26548 // C++] Quadratics  (0) 2022.12.21
[BOJ 24452 // C++] 交易計画 (Trade Plan)  (0) 2022.12.21

+ Recent posts