升級版三角形 圖形輸出

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; 
const int inf=0x3f3f3f3f;


int main(){
	char ch;
	scanf("%c",&ch);
	int n;
	if(ch>'0'&&ch<='9')	n=ch-'0';
	else n=ch-'A'+1;
	for(int i=0;i<n;i++){
		for(int j=0;j<n-i-1;j++)
			printf(" ");
		for(int j=0;j<(2*i+1)/2;j++){
			if(ch>'0'&&ch<='9')	printf("%d",j+1);
			else 	printf("%c",'A'+j);
		}
		for(int j=(2*i+1)/2;j>=0;j--)
			if(ch>'0'&&ch<='9')	printf("%d",j+1);
			else 	printf("%c",'A'+j);
		printf("\n");
	}
	return 0;
}

發佈了56 篇原創文章 · 獲贊 3 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章