Advertisement
Bojo96

Diamond

Oct 14th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. //URL FOR THE TASK: https://judge.softuni.bg/Contests/Practice/Index/533#9
  2.  
  3.  
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int size;
  11.     cin >> size;
  12.  
  13.     int exceptional_stars = 1;
  14.     if (size % 2 == 0)
  15.     {
  16.         exceptional_stars++;
  17.     }
  18.  
  19.     int exceptional_dashes = (size - exceptional_stars) / 2;
  20.  
  21.     //First Line
  22.     cout << string(exceptional_dashes, '-')
  23.         << string(exceptional_stars, '*')
  24.         << string(exceptional_dashes, '-')
  25.         << endl;
  26.  
  27.     //First half of body
  28.     int number_of_rows = (size - 1) / 2;
  29.     int number_of_inner_dashes = exceptional_stars;
  30.     for (int row = 1; row <= number_of_rows; row++)
  31.     {
  32.         int number_of_outer_dashes = (size - number_of_inner_dashes - 2) / 2;
  33.  
  34.         cout << string(number_of_outer_dashes, '-')
  35.             << "*"
  36.             << string(number_of_inner_dashes, '-')
  37.             << "*"
  38.             << string(number_of_outer_dashes, '-')
  39.             << endl;
  40.  
  41.         number_of_inner_dashes += 2;
  42.     }
  43.  
  44.     number_of_inner_dashes -= 4;
  45.     //Second half of body
  46.     for (int row = number_of_rows - 1; row > 0; row--)
  47.     {
  48.         int number_of_outer_dashes = (size - number_of_inner_dashes - 2) / 2;
  49.  
  50.         cout << string(number_of_outer_dashes, '-')
  51.             << "*"
  52.             << string(number_of_inner_dashes, '-')
  53.             << "*"
  54.             << string(number_of_outer_dashes, '-')
  55.             << endl;
  56.  
  57.         number_of_inner_dashes -= 2;
  58.     }
  59.  
  60.  
  61.     //Last Line
  62.     if (size > 2)
  63.     {
  64.         cout << string(exceptional_dashes, '-')
  65.             << string(exceptional_stars, '*')
  66.             << string(exceptional_dashes, '-')
  67.             << endl;
  68.     }
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement