字符串与日期处理-2

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cctype>
using namespace std;
const int maxn=10010;
const int N=10;

int main(){

	char ch;
	cin>>ch;
	
	if(isalpha(ch)){
		
		int n=ch-'A'+1;
		for(int i=1;i<=n;i++){
			
			string space(n-i,' ');
			cout<<space;
			
			for(int j=1;j<=i;j++)				
				cout<<(char)('A'+j-1);	//因为用cout输出的时候,
				//如果你把字符的ASCII来直接计算,会当成整数输出的
			
			for(int j=i-1;j>=1;j--)
				cout<<(char)('A'+j-1);
				
			cout<<endl;			
		}
		
	}
	else{
			int n=ch-'0';
		for(int i=1;i<=n;i++){
			
			string space(n-i,' ');
			cout<<space;
			
			for(int j=1;j<=i;j++)				
				cout<<j;	  
			
			for(int j=i-1;j>=1;j--)
				cout<<j;
				
			cout<<endl;			
		}
		
	}
	
	return 0;
}
发布了138 篇原创文章 · 获赞 18 · 访问量 7049

猜你喜欢

转载自blog.csdn.net/qq_924485343/article/details/104334335