1027 打印沙漏 c++
作者:互联网
一级标题 1027 打印沙漏 c++
#include<iostream>
using namespace std;
#include<iomanip>
int main()
{
int sum = 0;
cin >> sum;
char st;
cin >> st;
int count = 1;
int line=0;
if (sum<7)
{
cout << st << endl;
cout << sum - 1;
}
else
{
int i = 3;
for (i = 3; i < sum; i+=2)
{
count += 2*i;
line++;
if (count > sum)
{
count -= 2 * i;
i -=2;
break;
}
}
int j = 0;
for (j; j < line; j++)
{
cout << setw(j) << "";
int column = i;
for (int a = 0; a < column; a++)
{
cout << st;
}
i -= 2;
cout<<endl;
}
j -= 2;
i += 4;
for (j; j >=0; j--)
{
cout << setw(j) << "";
int column = i;
for (int a = 0; a < column; a++)
{
cout << st;
}
i += 2;
cout << endl;
}
cout << sum-count;
}
return 0;
}
标签:count,1027,cout,沙漏,int,sum,c++,line 来源: https://blog.csdn.net/qq_53336225/article/details/120372795