fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(int argc, char* argv[]) {
  5.  
  6. int startNum = 0;
  7. cin >> startNum;
  8.  
  9. if (startNum <= 0) return 1;
  10.  
  11. cout << startNum << endl;
  12. int numCols = startNum;
  13. int numRows = (startNum + 1) / 2;
  14.  
  15. if (numCols % 2 == 0) {
  16. ++numRows;
  17. }
  18.  
  19. int numFields = numCols * numRows;
  20.  
  21. for (int currentField = 0; currentField < numFields; ++currentField) {
  22. int currentRow = currentField / numCols;
  23. int currentCol = currentField % numCols;
  24.  
  25. if (currentCol < currentRow) cout << "-";
  26. else if (currentCol > (numCols - currentRow - 1))
  27. if (currentRow == numRows - 1 && currentCol == numCols / 2) cout << "^";
  28. else cout << "_";
  29. else cout << "*";
  30.  
  31. if (currentCol == numCols - 1) cout << endl;
  32. }
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3344KB
stdin
39
stdout
39
***************************************
-*************************************_
--***********************************__
---*********************************___
----*******************************____
-----*****************************_____
------***************************______
-------*************************_______
--------***********************________
---------*********************_________
----------*******************__________
-----------*****************___________
------------***************____________
-------------*************_____________
--------------***********______________
---------------*********_______________
----------------*******________________
-----------------*****_________________
------------------***__________________
-------------------*___________________