-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled2.cpp
47 lines (45 loc) · 1.14 KB
/
Untitled2.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
#include <fstream>
int main() {
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int n;
in >> n;
int **a = new int*[n];
for (int i = 0; i < n; i++) {
a[i] = new int[n];
for (int j = 0; j < n; j++)
in >> a[i][j];
}
int *src = new int[n]; for (int i = 0; i < n; i++) src[i] = 0;
int *des = new int[n]; for (int i = 0; i < n; i++) des[i] = 0;
int csrc = 0, cdes = 0;
int f1, f2;
for (int i = 0; i < n; i++) {
f1 = f2 = 0;
for (int j = 0; j < n; j++) // sum of line
f1 += a[i][j];
for (int j = 0; j < n; j++)
f2 += a[j][i];
if (f1 == 0) {
cdes++;
des[i] = i + 1;
}
if (f2 == 0) {
csrc++;
src[i] = i + 1;
}
}
out << csrc;
for (int i = 0; i < n; i++)
if (src[i] != 0) out << ' ' << src[i];
out << endl << cdes;
for (int i = 0; i < n; i++)
if (des[i] != 0) out << ' ' << des[i];
in.close();
out.close();
for (int i = 0; i < n; i++)
delete [] a[i];
delete [] a;
return 0;
}