codeup27944 星号空心六边形
时空限制 1000ms/128MB
题目描述
输入正整数n,输出星号空心六边形。
输入
一个正整数n
输出
输出星号空心六边形
样例输入
6
样例输出
******
* *
* *
* *
* *
* *
* *
* *
* *
* *
******
代码
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
for (int i=1; i<=n; i++){
for (int j=1; j<=n-i; j++) cout<<" ";
if (i==1)
for (int j=1; j<=n+2*i-2; j++) cout<<"*";
else {
cout<<"*";
for (int j=1; j<=n+2*i-4; j++) cout<<" ";
cout<<"*";
}
cout<<endl;
}
for (int i=n-1; i>=1; i--){
for (int j=1; j<=n-i; j++) cout<<" ";
if (i==1)
for (int j=1; j<=n+2*i-2; j++) cout<<"*";
else {
cout<<"*";
for (int j=1; j<=n+2*i-4; j++) cout<<" ";
cout<<"*";
}
cout<<endl;
}
return 0;
}
最后
以上就是健忘睫毛最近收集整理的关于codeup27944 星号空心六边形的全部内容,更多相关codeup27944内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复