Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- const int val = -10000000;
- int n, m; cin >> n >> m;
- int max;
- if (n > m) {
- max = n;
- }
- else {
- max = m;
- }
- int **a = new int*[max + 1];
- for (int i = 1; i <= max; i++) {
- a[i] = new int[max + 1];
- }
- for (int i = 1; i <= max; i++) {
- for (int j = 1; j <= max; j++) {
- a[i][j] = val;
- }
- }
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= m; j++) {
- cin >> a[i][j];
- }
- }
- for (int i = 1; i <= max; i++) {
- for (int j = 1; j <= i; j++) {
- if (a[i - j + 1][j] != val) {
- cout << a[i - j + 1][j] << " ";
- }
- }
- cout << endl;
- }
- for (int j = 2; j <= max; j++) {
- for (int i = max; i >= j; i--) {
- if (a[i][max - i + j] != val) {
- cout << a[i][max - i + j] << " ";
- }
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement