-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1027.cpp
60 lines (50 loc) · 1.05 KB
/
1027.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
using namespace std;
int main()
{
int cnt;char ans;
cin>>cnt>>ans;
int half_row=0;
int temp=(cnt-1)/2,sum=0;
for(half_row=1; ;half_row++)
{
sum+=(1+half_row*2);
if(sum>temp)
{
sum=sum-(half_row*2+1);
half_row--;
break;
}
}
int extra = cnt-(sum*2+1);
// cout<<half_row;
int space=0;
for(int i=0;i<half_row;i++)
{
space=i;
while((space--)>0)cout<<" ";
int cnt=half_row-i;
for(int j=0;j<cnt*2+1;j++)
cout<<ans;
while((space--)>0)cout<<" ";
cout<<"\n";
}
space= half_row;
if(cnt>0)
{
while((space--)>0)
cout<<" ";
cout<<ans;
cout<<endl;
}
for(int i=half_row-1;i>=0;i--)
{
space=i;
while((space--)>0)cout<<" ";
int cnt=half_row-i;
for(int j=0;j<cnt*2+1;j++)
cout<<ans;
cout<<"\n";
}
cout<<extra<<endl;
}