把这个题弄得稍微高级一点点
查看原帖
把这个题弄得稍微高级一点点
1687710
CorinTide楼主2025/7/29 10:41
#include<bits/stdc++.h>
#include<string>
using namespace std;
void print(int n){
	for(int a=1;a!=n;a+=2){//打印上半部分的 
		int space=(n/2)+1-((a/2)+1);//算每行空格的数量 
		while(space--){//打印每行的空格 
			cout<<' ';
		}
		int xb=a;//获取本行需要打印的字符 
		while(xb--){//打印每行的字符 
			cout<<'*';
		}
		cout<<endl;
	}
	for(int a=n;a!=-1;a-=2){//打印下半部分(包括最中间部分的) 
		int space=(n/2)+1-((a/2)+1);//算每行空格的数量 
		while(space--){//打印每行的空格 
			cout<<' ';
		}
		int xb=a;//获取本行需要打印的字符 
		while(xb--){//打印每行的字符 
			cout<<'*';
		}
		cout<<endl;
	}
}
int main(){
	print(11);//输入对角线长度,为奇数 
	return 0;
}

2025/7/29 10:41
加载中...