FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/F14TwoDimensionalArrays/SquateMatrix.cpp at main · roydevashish/cpp · GitHub
roydevashish
/
cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
F14TwoDimensionalArrays
/
SquateMatrix.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
116 lines (93 loc) · 2.25 KB
Breadcrumbs
cpp
/
F14TwoDimensionalArrays
/
SquateMatrix.cpp
Copy path
File metadata and controls
116 lines (93 loc) · 2.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Title: Square Matrix
Problem statement
You are given a 2D array of integers ‘A’ of length ’N’x’M’, where ‘N’ is the number of rows and ‘M’
is the number of columns. Check if the given array forms a square matrix and returns its diagonal
elements.
A Square matrix is one that has an equal number of rows and columns.
Example:
Input:
3 3
1 2 3
4 5 6
7 8 9
Output:
YES
1 5 9
Explanation:
The number of rows and columns is equal, so the given array forms a square matrix.
Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of the input contains an integer 'T’, Denoting the number of test cases.
The first line of each test case contains two integers ‘N’ and ‘M’ separated by space.
The next ’N’ lines in each test contain ‘M’ integers separated by space.
Output format:
Return a pair of strings and an array, If the matrix is a square matrix, return ‘YES’with the array
containing the diagonal elements, else return ‘NO’ with an empty array.
Constraints :
1 <= T <= 10
1 <= N,M <= 50
1 <= A[i] <= 1000
Time Limit: 1 sec
Sample Input 1:
2
3 3
1 2 3
4 5 6
7 8 9
2 3
1 3 2
4 5 5
Sample Output 1:
YES
1 5 9
NO
Explanation Of Sample Input 1 :
Test 1:
The number of rows and columns is equal, so the given array forms a square matrix.
Test 2:
The number of rows and columns is not equal, so the given array doesn’t form a square matrix.
Sample Input 2 :
2
2 2
1 2
2 1
1 1
3
Sample Output 2 :
YES
1 1
YES
3
*/
#
include
<
iostream
>
using
namespace
std
;
int
main
(){
int
t;
cin >> t;
for
(
int
test_case =
0
; test_case < t; test_case++) {
int
n, m;
cin >> n >> m;
int
input_array[n][m];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j < m; j++) {
cin >> input_array[i][j];
}
}
//
SquareMatrix(input_array, n, m);
if
(n == m) {
cout <<
"
YES
"
<< endl;
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j < m; j++) {
if
(i == j) {
cout << input_array[i][j] <<
"
"
;
}
}
}
cout << endl;
}
else
{
cout <<
"
NO
"
<< endl;
}
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL