1.只需要打印左边的空格。
2.把沙漏分为上下两部分打印。
3.n<7时只打印出一个符号
#include<iostream>
using namespace std;
int main()
{
int n,max=3;
char c;
cin>>n>>c;
int m=n-1;
if(n<7)
{
cout<<c<<endl;
cout<<n-1<<endl;
}
else
{
while(1)
{
m=m-2*max;
if(m<=max)
break;
max+=2;
}
for(int i=1;i<=max/2+1;i++)
{
for(int j=1;j<=i-1;j++)
{
cout<<' ';
}
for(int j=1;j<=max-(i-1)*2;j++)
{
cout<<c;
}
cout<<endl;
}
for(int i=max/2+2;i<=max;i++)
{
for(int j=1;j<=max-i;j++)
{
cout<<' ';
}
for(int j=1;j<=max-(max-i)*2;j++)
{
cout<<c;
}
cout<<endl;
}
cout<<m<<endl;
}
return 0;
}