#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
int n;
char s;
cin >> n >> s;
int sum = 1;
int h = sqrt((n + 1) / 2); //沙漏上层的高度(直到一个字符)
for (int i = 0; i < h; i++)
{
for (int j = 0; j < i; j++)cout << " "; //输出空格的数量
for (int j = 0; j < 2 * (h - i) - 1; j++) //输出字符的数量
{
cout << s; //每次循环结束需要换行
}
cout << endl;
}
for (int i = 2; i <= h; i++)
{
for (int j = 0; j < h - i; j++)cout << " "; //每一次输出空格的数量
for (int j = 0; j < 2 * i - 1; j++) //每一次输出字符的数量
{
cout << s;
}
cout << endl; //每次循环结束需要换行
}
cout << n - 2 * h * h + 1;
return 0;
}
其实就是一个模拟,毫无算法可言!