Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void Print(vector<vector<int>> a) {
- for (int i = 0; i < (int) a.size(); i++) {
- for (int j = 0; j < (int) a[i].size(); j++) {
- cout << a[i][j] << " ";
- }
- cout << '\n';
- }
- cout << '\n';
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- // enter size of square matrix
- int n;
- cin >> n;
- // upper-left right triangle:
- vector<vector<int>> a(n, vector<int>(n, 0));
- a[0][0] = 1;
- for (int i = 1; i + 1 < n; i++) {
- for (int j = i; j >= 0; j--) {
- a[i - j][j] = 1;
- }
- }
- Print(a);
- // bottom-right right triangle
- a[n - 1][n - 1] = 1;
- for (int j = n - 2; j > 0; j--) {
- for (int i = 0; i < n - j; i++) {
- a[n - 1 - i][j + i] = 1;
- }
- }
- Print(a);
- // other diagonal
- for (int i = n - 1; i >= 0; i--) {
- a[i][n - 1 - i] = 1;
- }
- Print(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement