0
点赞
收藏
分享

微信扫一扫

计蒜客02:输出一个复杂的三角形

九点韶留学 2022-01-12 阅读 30
#include <iostream>

using namespace std;

int main() {
	int c;
	cin >> c;
	
	if(c >= 'A' && c <= 'Z'){
		for(int i = 1; i <= c - 'A' + 1; i++){
			for(int j = 1; j <= c - 'A' + 1 - i; j++){
				cout << " ";	
			}
			for(int j = 1; j <= i; j++){
				cout << (char)('A' + j - 1);
			}
			for(int j = i - 1; j >= 0; j--){
				cout << (char)('A' + j - 1);
			}
			
			cout << endl;
		}
	}else {
		for(int i = 1; i <= c - '1' + 1; i++){
			for(int j = 1; j <= c - '1' + 1 - i; j++){
				cout << " ";	
			}
			for(int j = 1; j <= i; j++){
				cout << (char)('1' + j - 1);
			}
			for(int j = i - 1; j >= 0; j--){
				cout << (char)('1' + j - 1);
			}
			
			cout << endl;
		}
	}
	
	return 0;
}

举报

相关推荐

0 条评论