这题要注意一点符号后面不打印空格。
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int n,i,j,l;
char ch;
cin>>n>>ch;
l=(int)sqrt((n+1)/2.0);
int t=l*2-1,k=0,tp=l;
int res=n-(2*l*l-1);
j=t;
while(tp--)
{
for(i=0;i<k;i++) cout<<" ";
for(i=0;i<j;i++) cout<<ch;
k++;
j-=2;
cout<<endl;
}
l=l-1;
k-=2;
j+=4;
while(l--)
{
for(i=0;i<k;i++) cout<<" ";
for(i=0;i<j;i++) cout<<ch;
k--;
j+=2;
cout<<endl;
}
cout<<res<<endl;
return 0;
}