码迷,mamicode.com
首页 > 其他好文 > 详细

pat沙漏我写的

时间:2016-09-03 18:15:30      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

#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沙漏我写的

标签:

原文地址:http://www.cnblogs.com/code666/p/5837519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!