首页 > 代码库 > 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沙漏我写的
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。