From 32ddae76a51ced3f3a134c5373ed4ce19024e52a Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 29 Oct 2021 10:00:17 +0300 Subject: Fixed math of solution to exercise 13 --- Sem. 03/Solutions/13. Dumbbell.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sem. 03/Solutions/13. Dumbbell.cpp b/Sem. 03/Solutions/13. Dumbbell.cpp index bc0aad5..7db650a 100644 --- a/Sem. 03/Solutions/13. Dumbbell.cpp +++ b/Sem. 03/Solutions/13. Dumbbell.cpp @@ -7,19 +7,19 @@ int main() int n; cin >> n; - int rowWidth = 5 * n / 2; - int evenness = 1 - n % 2; - for (int i = 0; i < n; i++) + int rowWidth = 3 * n - 2; + + for (int row = 0; row < n; row++) { - if (i == 0 || i == n - 1) + if (row == 0 || row == n - 1) { - for (int j = 0; j < rowWidth; j++) - cout << ((j == n || j == n + evenness) ? " " : "."); + for (int col = 0; col < rowWidth; col++) + cout << ((col >= n && col <= rowWidth - n - 1) ? " " : "."); } else { - for (int j = 0; j < rowWidth; j++) - cout << ((j == 1 || j == 1 + evenness || j == rowWidth - 2 || j == rowWidth - 2 - evenness) ? " " : "."); + for (int col = 0; col < rowWidth; col++) + cout << (((col >= 1 && col <= n - 2) || (col >= rowWidth - n + 1 && col <= rowWidth - 2)) ? " " : "."); } cout << endl; } -- cgit v1.3.1-23-gd82d