Last active
July 9, 2021 14:54
-
-
Save Aldhanekaa/96b57921f07d80f9fe12eeed29319804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstdio> | |
| /*n = 1 | |
| 1 | |
| n = 2 | |
| 1 1 1 | |
| 1 2 1 | |
| 1 1 1 | |
| n=3 | |
| 1 1 1 1 1 | |
| 1 2 2 2 1 | |
| 1 2 3 2 1 | |
| 1 2 2 2 1 | |
| 1 1 1 1 1 | |
| n=4 | |
| 1 1 1 1 1 1 1 | |
| 1 2 2 2 2 2 1 | |
| 1 2 3 3 3 2 1 | |
| 1 2 3 4 3 2 1 | |
| 1 2 3 3 3 2 1 | |
| 1 2 2 2 2 2 1 | |
| 1 1 1 1 1 1 1 | |
| 1 1 1 | 1 | 1 1 1 | | |
| 1 2 2 | 2 | 2 2 1 -> row < n | |
| 1 2 3 | 3 | 3 2 1 | | |
| - - - - - - - - - | |
| 1 2 3 | 4 | 3 2 1 -> row == n | |
| - - - - - - - - - | |
| 1 2 3 | 3 | 3 2 1 | | |
| 1 2 2 | 2 | 2 2 1 -> row > n | |
| 1 1 1 | 1 | 1 1 1 | | |
| */ | |
| void printQuadrant(int row, int column); | |
| void printXAxis(int n, int column); | |
| int main() { | |
| int n; | |
| std::cin >> n; | |
| int width = n + (n - 1); | |
| int height = width; | |
| for (int row = 1; row <= height; row++) { // row | |
| for (int column = 1; column <= width; column++) { // column | |
| if (row < n) { | |
| if (column != n) { | |
| if (column < n) | |
| { | |
| printQuadrant(row, column); | |
| } | |
| else { | |
| printQuadrant(row, n - (column - n)); | |
| } | |
| } | |
| else | |
| { | |
| std::cout << row << " "; | |
| } | |
| } /* if the current row is equal to the input */ else if (row == n) { | |
| printXAxis(n, column); | |
| } | |
| else if (row > n) | |
| { | |
| if (column != n) { | |
| if (column < n) | |
| { | |
| printQuadrant(n - (row - n), column); | |
| } | |
| else { | |
| printQuadrant(n - (row - n), n - (column - n)); | |
| } | |
| } | |
| else | |
| { | |
| std::cout << n - (row - n) << " "; | |
| } | |
| } | |
| } | |
| std::cout << "\n"; | |
| } | |
| } | |
| void printQuadrant(int row, int column) { | |
| if (row > column) { | |
| std::cout << column << " "; | |
| } | |
| if (row <= column) { | |
| std::cout << row << " "; | |
| } | |
| } | |
| void printXAxis(int n, int column) { | |
| if (column != n) { | |
| // Left side X Axis | |
| if (column < n) { | |
| std::cout << column << " "; | |
| } /* Right Side X axis */ else { | |
| printf("%d ", n - (column - n)); | |
| } | |
| } /* the origin point */ else{ | |
| std::cout << column << " "; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment