题解(求点赞)
2023-08-10 16:26:09
发布于:浙江
6阅读
0回复
0点赞
#include<iostream>
using namespace std;
int x,y;
int main()
{
int n;
cin>>n;
int x=n-1,y=3;
while(1)
{
if(x>=y*2)
{
x-=y*2;
}
else
{
y-=2;
break;
}
y+=2;
}
for(int i=y;i>=1;i-=2)
{
for(int j=1;j<=(y-i)/2;j++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"*";
for(int j=1;j<=(y-i)/2;j++)
cout<<" ";
cout<<"\n";
}
for(int i=3;i<=y;i+=2)
{
for(int j=1;j<=(y-i)/2;j++)
cout<<" ";
for(int j=1;j<=i;j++)
cout<<"*";
for(int j=1;j<=(y-i)/2;j++)
cout<<" ";
cout<<"\n";
}
cout<<x;
return 0;
}
这里空空如也
有帮助,赞一个