Advertisement
AquaBlitz11

Alphabet Rangoli

Jun 18th, 2020
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int linesize;
  5. int n;
  6.  
  7. void rep(char c, int t)
  8. {
  9.     for (int i = 0; i < t; ++i)
  10.         printf("%c", c);
  11. }
  12.  
  13. void printline(int i)
  14. {
  15.     int mid = 4*i-3; // size of middle portion c-b-a-b-c
  16.     int lr = (linesize-mid)/2;
  17.     rep('-', lr);
  18.     for (int j = i-1; j >= 1; --j)
  19.         printf("%c-", ('a'+n-i)+j);
  20.     printf("%c", 'a'+n-i);
  21.     for (int j = 1; j <= i-1; ++j)
  22.         printf("-%c", ('a'+n-i)+j);
  23.     rep('-', lr);
  24.     printf("\n");
  25. }
  26.  
  27. int main()
  28. {
  29.     scanf("%d", &n);
  30.     linesize = 4*n-3;
  31.  
  32.     for (int i = 1; i <= n; ++i)
  33.         printline(i);
  34.     for (int i = n-1; i >= 1; --i)
  35.         printline(i);
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement