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;
}