首页 > 代码库 > pat沙漏我写的

pat沙漏我写的

#include<iostream>
using namespace std;
int main()
{
int a, i, k, j, n1,n2;
int b = 7;
int n = 3;
char ch;
cin >> a >> ch;
if (a < 7)
{
cout << ch << endl;
cout << a - 1 << endl;
exit(0);
}
while (a >= b)
{
b = 2 * n *n - 1;
n = n + 1;
}
n = n - 2;
b = 2 * n *n - 1;
n1 = n;
n2 = n;
for (i = 1; i <= n1-1; i++)
{
for (k = 1; k <= i - 1; k++) cout << " ";
for (j = 1; j <= 2 * n2- 1; j++) cout << ch;
cout << endl; n2 = n2 - 1;
}
for (i = 1; i <= n; i++)
{
for (k = 1; k <= n - i; k++) cout << " ";
for (j = 1; j <= 2 * i - 1; j++) cout << ch;
cout << endl;
}
cout << a - b;
}

pat沙漏我写的