Advertisement
DidiMilikina

05. Snowflake

Oct 31st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin >> n;
  10.     int height = n * 2 + 1;
  11.     int width = 2 * n + 3;
  12.  
  13.     int number_of_inner_dots = n;
  14.  
  15.     //First half
  16.     for (int row = 0; row < n - 1; row++)
  17.     {
  18.         int number_of_outer_dots = row;
  19.         cout
  20.             << string(number_of_outer_dots, '.')
  21.             << "*"
  22.             << string(number_of_inner_dots, '.')
  23.             << "*"
  24.             << string(number_of_inner_dots, '.')
  25.             << "*"
  26.             << string(number_of_outer_dots, '.')
  27.             << endl;
  28.         number_of_inner_dots--;
  29.     }
  30.  
  31.     //Middle
  32.     int middle_outer_dots = (width - 5) / 2;
  33.     cout
  34.         << string(middle_outer_dots, '.')
  35.         << string(5, '*')
  36.         << string(middle_outer_dots, '.')
  37.         << endl;
  38.     cout << string(width, '*') << endl;
  39.     cout
  40.         << string(middle_outer_dots, '.')
  41.         << string(5, '*')
  42.         << string(middle_outer_dots, '.')
  43.         << endl;
  44.  
  45.     //Second half
  46.     for (int row = n-2; row >= 0; row--)
  47.     {
  48.         number_of_inner_dots++;
  49.         int number_of_outer_dots = row;
  50.         cout
  51.             << string(number_of_outer_dots, '.')
  52.             << "*"
  53.             << string(number_of_inner_dots, '.')
  54.             << "*"
  55.             << string(number_of_inner_dots, '.')
  56.             << "*"
  57.             << string(number_of_outer_dots, '.')
  58.             << endl;
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement