这道题目感觉还是蛮复杂的
要一步一步算下来
#include<cstdio>
#include<cmath>
int main()
{
int n,x,res;
char c;
scanf("%d %c", &n, &c);
x = floor(sqrt(2.0*(1+n)))-1;
if (x % 2 == 0) x = x - 1;
res = n - (1 + x)*(1 + x) / 2 + 1;
for (int i = x; i >=1; i-=2)//输出上三角
{
for (int j = 0; j <( x-i)/2; j++)
{
printf(" ");
}
for (int k = 0; k < i; k++)
{
printf("%c", c);
}
printf("\n");
}
for (int i = 3; i <= x; i += 2)
{
for (int j = 0; j < (x - i) / 2; j++)
{
printf(" ");
}
for (int k = 0; k < i; k++)
{
printf("%c", c);
}
printf("\n");
}
printf("%d", res);
return 0;
}