/*
Author: Nace Hudobivnik
School: St.Stanislav's Institution Skofijska klasicna
gimnazija
Division: Novice
Country: Slovenia
The script was compiled in Linux operating system, with
following command:
g++ reversi.cpp -o reversi
It is possible to build it in windows with Dev-C++ 5.0 beta
9.2 (4.9.9.2) with Mingw/GCC 3.4.2
IMPORTANT NOTE!
When thesting this program, please input the data exactly as
it was shown on instructions.
This means that you have to input a comma followed by a
space, between each of five strings, as specified in instructions.
Valid sample input:
2, 5D, 5E, 2, 4E, 4D
3, 1D, 2E, 2F, 3, 1E, 2D, 3F
5, 7B, 7C, 5C, 5E, 3B, 3, 5D, 6C, 4C
3, 1A, 2A, 3A, 3, 1C, 2C, 3C
4, 3E, 3G, 4C, 5D, 4, 4D, 4E, 4F, 5C
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int grid[10][10];
struct Tvect{
int x; int y; int
st;
} v,vpr;
bool operator<(Tvect a, Tvect b) {
return
a.st<b.st;
}
vector<Tvect> list;
void check(int x, int y, int a, int b, int nr){
if((grid[x+a][y+b]
== 1) && (x+a < 9) && (x+a > 0) && (y+b < 9)
&& (y+b > 0)){
if(nr>0){
v.x = x;
v.y = y;
v.st = nr;
if(!list.empty()){
vpr =
list.back();
if((vpr.x==v.x)&&(vpr.y==v.y)){
v.st += vpr.st;
list.pop_back();
}
}
list.push_back(v);
}
} else
if(grid[x+a][y+b] == 2){
if(a>0) a++;
if(a<0) a--;
if(b>0) b++;
if(b<0) b--;
nr++;
check(x,y,a,b,nr);
}
}
int main(){
char c;
int n,y,x;
for(int
z=0;z<5;z++){
//clear the grid
& vector
for(int
i=0;i<10;i++)
for(int
j=0;j<10;j++)
grid[j][i]
= 0;
list.clear();
//read the line
scanf("%d",&n);
for(int
i=0;i<n;i++){
scanf(",
%d%c",&y,&c);
x = c-'A'+1;
grid[x][y] = 1;
}
scanf(",
%d",&n);
for(int
i=0;i<n;i++){
scanf(",
%d%c",&y,&c);
x = c-'A'+1;
grid[x][y] = 2;
}
//bruteforce
check
for(int
i=1;i<9;i++)
for(int
j=1;j<9;j++)
if(grid[j][i]
== 0)
for(int a=-1;a<2;a++)
for(int b=-1;b<2;b++)
if(!((a==b) && (a == 0)))
check(j,i,a,b,0);
sort(list.begin(),list.end());
if(list.empty()){
cout <<
"NONE" << endl;
} else {
v =
list.back();
x = v.st;
while(!list.empty()){
c =
v.x-1+'A';
cout
<< v.y << c;
list.pop_back();
v =
list.back();
if(v.st<x)
break;
if(list.size()
> 0) cout << ", ";
}
cout <<
endl;
}
}
return 0;
}