fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. char S;
  6. cin >> S;
  7. int w, h, t;
  8. cin >> w >> h >> t;
  9. char *s1 = new char[w];
  10. for (int i = 0; i < w; i++) s1[i] = S;
  11. int times;
  12. times = (t * h) - (t - 1);
  13. int num = 0;
  14. bool flag = true;
  15. char *tmp;
  16. for (int i = 1; i <=times; i++) {
  17. if(num < 0) num = 0;
  18. tmp = new char [num];
  19. for (int i = 0; i < num; i++) tmp[i] = ' ';
  20. cout << tmp;
  21. if (i % 2) cout << s1;
  22. else {
  23. for (int q = 0; q < w / 2 + w % 2; q++) {
  24. cout << S;
  25. if (q != w / 2 + w % 2 - 1) cout << " ";
  26. }
  27. }
  28. if (!flag) num--;
  29. else num++;
  30. if (num == h / 2) flag = false;
  31. if (num == 0) flag = true;
  32. if (num == h / 2 && h % 2 == 0) num--;
  33. if (i != times) cout << endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 15240KB
stdin
W 7 9 1
stdout
WWWWWWW
 W W W W
  WWWWWWW
   W W W W
    WWWWWWW
   W W W W
  WWWWWWW
 W W W W
WWWWWWW