-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1906A.cpp
More file actions
105 lines (84 loc) · 2.59 KB
/
Copy path1906A.cpp
File metadata and controls
105 lines (84 loc) · 2.59 KB
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
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool isNeighbour(pair<int, int> p1, pair<int, int> p2);
int main () {
vector<vector<char>> grid(4, vector<char>(4));
int A = 0, B = 0, C = 0;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'A') {
A++;
} else if (grid[i][j] == 'B') {
B++;
} else if (grid[i][j] == 'C') {
C++;
}
}
}
if (A == 0 && B == 0) {
cout << "CCC" << endl;
} else if (B == 0 && C == 0) {
cout << "AAA" << endl;
} else if (A == 0 && C == 0) {
cout << "BBB" << endl;
} else {
/*
{"AA" : {(x1, y1), (x2, y2)}}
*/
vector<pair<string, pair<pair<int, int>, pair<int, int>>>> com1;
string ans;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
for (int k = 1; k <= 3; k++) {
for (int l = 1; l <= 3; l++) {
if (isNeighbour({i, j}, {k, l})) {
string temp;
temp += grid[i][j];
temp += grid[k][l];
com1.push_back({temp, {{i, j}, {k, l}}});
}
}
}
}
}
sort(com1.begin(), com1.end());
ans += com1[0].first;
pair<string, pair<pair<int, int>, pair<int, int>>> equals = com1[0];
vector<pair<string, pair<pair<int, int>, pair<int, int>>>> com2;
com2.push_back(com1[0]);
for (ll i = 1; i < com1.size(); i++) {
if (com1[i].first != equals.first) {
break;
}
com2.push_back(com1[i]);
}
vector<string> com3;
for (auto it : com2) {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (i == it.second.first.first && j == it.second.first.second) {
continue;
} else if (isNeighbour({i, j}, it.second.second)) {
string temp = "";
temp += ans;
temp += grid[i][j];
com3.push_back(temp);
}
}
}
}
sort(com3.begin(), com3.end());
cout << com3[0] << endl;
}
}
bool isNeighbour(pair<int, int> p1, pair<int, int> p2) {
if (p1 == p2) {
return false;
} else if ((abs(p1.first-p2.first) <= 1) && (abs(p1.second-p2.second) <= 1)) {
return true;
} else {
return false;
}
}