/
InfinityPattern.cpp
76 lines (61 loc) · 1.02 KB
/
InfinityPattern.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Infinity Symbol Pattern
Given a matrix M of size N*N as input, the program must print the output as shown in the Example Input/Output section.
Boundary Condition(s):
2 <= N <= 50
Input Format:
The first line contains the value of N.
The next N lines contain N values each separated by space.
Output Format:
The first line contains the desired output as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
3
1 2 3
5 6 7
2 3 4
Output:
1 6 4 7 3 6 2 5 1
Example Input/Output 2:
Input:
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
1 6 11 16 12 8 4 7 10 13 9 5 1
*/
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int n;
cin >> n;
int a[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin >> a[i][j];
}
}
for(int i=0;i<n;i++)
{
cout << a[i][i] << " ";
}
for(int i=n-2;i>=0;i--)
{
cout << a[i][n-1] << " ";
}
int k = n-2;
for(int i=1;i<n;i++)
{
cout << a[i][k] << " ";
k--;
}
for(int i=n-2;i>=0;i--)
{
cout << a[i][0] << " ";
}
}