-
Notifications
You must be signed in to change notification settings - Fork 1
/
7.cpp
53 lines (42 loc) · 1023 Bytes
/
7.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
// O(n * m * max(n, m))
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
int n, m;
char board[110][110];
inline bool valid(int x, int y) {
for (int i = 0; i < m; ++i) {
if (i != y && board[x][i] == board[x][y]) {
return false;
}
}
for (int i = 0; i < n; ++i) {
if (i != x && board[i][y] == board[x][y]) {
return false;
}
}
return true;
}
int main() {
FAST_IO;
// FILE_IO;
string res = "";
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> board[i][j];
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (valid(i, j)) {
res += board[i][j];
}
}
}
cout << res;
return 0;
}