You are given an integer, . Your task is to print an alphabet rangoli of size . (Rangoli is a form of Indian folk art based on creation of patterns.)
Different sizes of alphabet rangoli are shown below:
#size 3 ----c---- --c-b-c-- c-b-a-b-c --c-b-c-- ----c---- #size 5 --------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e-------- #size 10 ------------------j------------------ ----------------j-i-j---------------- --------------j-i-h-i-j-------------- ------------j-i-h-g-h-i-j------------ ----------j-i-h-g-f-g-h-i-j---------- --------j-i-h-g-f-e-f-g-h-i-j-------- ------j-i-h-g-f-e-d-e-f-g-h-i-j------ ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j---- --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j-- j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j-- ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j---- ------j-i-h-g-f-e-d-e-f-g-h-i-j------ --------j-i-h-g-f-e-f-g-h-i-j-------- ----------j-i-h-g-f-g-h-i-j---------- ------------j-i-h-g-h-i-j------------ --------------j-i-h-i-j-------------- ----------------j-i-j---------------- ------------------j------------------The center of the rangoli has the first alphabet letter a, and the boundary has the alphabet letter (in alphabetical order).
Input Format
Only one line of input containing , the size of the rangoli.
Constraints
Output Format
Print the alphabet rangoli in the format explained above.
Sample Input
5Sample Output
--------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e--------代码如下:
#include<bits/stdc++.h> using namespace std; int main(){ int n; scanf("%d",&n); char k=97+n-1; for(int i=1;i<=n;i++){ for(int j=1;j<=4*n-3;j++){ if(j>=2*(n-i)+1&&j<=2*(n+i)-3){ if(j%2){ if(j<(4*n-3)/2+1) printf("%c",k--); else if(j==(4*n-3)/2+1) printf("%c",k); else printf("%c",++k); } else printf("-"); } else{ printf("-"); } } printf("\n"); } for(int i=n+1;i<=2*n-1;i++){ for(int j=1;j<=4*n-3;j++){ if(j>=2*(i-n)+1&&j<=2*(3*n-i)-3){ if(j%2){ if(j<(4*n-3)/2+1) printf("%c",k--); else if(j==(4*n-3)/2+1) printf("%c",k); else printf("%c",++k); } else printf("-"); } else{ printf("-"); } } printf("\n"); } return 0; }
