Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*include needed headers here */
using namespace std;
typedef map<char, bool> pmap;
void main()
{
int T;
//freopen("C:\\input1.txt","r",stdin);
//freopen("C:\\outp.txt","w",stdout);
cin >> T;
for (int kk = 0; kk < T; kk++) {
int jj = 0, k = 0, j, y22, x22, lt[10000], l, ll, v1, v2, tt = 0, x = 0, y = 0,
maxx, maxy, minx, miny;
vector<int> k1, k2, x11, y11;
string forward, reverse;
pmap M;
vector<bool> n, e, s, w;
bool n1[10005], e1[10005], w1[10005], s1[10005];
memset(n1, 0, sizeof(n1));
memset(e1, 0, sizeof(e1));
memset(w1, 0, sizeof(w1));
memset(s1, 0, sizeof(s1));
char x1[4] = { 'N', 'E', 'S', 'W' };
char x2[4] = { 'E', 'S', 'W', 'N' };
char x3[4] = { 'S', 'W', 'N', 'E' };
char x4[4] = { 'W', 'N', 'E', 'S' };
char t1, t2, t3, t4, current;
cin >> forward;
cin >> reverse;
for (j = 0; j < forward.size(); j++) {
current = forward.at(j);
t1 = x1[jj];
t2 = x2[jj];
t3 = x3[jj];
t4 = x4[jj];
switch (current) {
case 'W':
M[t1] = 1;
break;
case 'L':
M[t2] = 1;
if (jj == 0)
jj = 3;
else
jj--;
break;
case 'R':
if (forward.size() - 1 != j)
if (forward.at(j + 1) == 'R') {
M[t1] = 1;
M[t2] = 0;
M[t3] = 0;
M[t4] = 0;
j++;
if (jj == 2)
jj = 0;
else if (jj == 3)
jj = 1;
else
jj = jj + 2;
}
else {
M[t1] = 1;
M[t2] = 0;
M[t3] = 0;
M[t4] = 1;
if (jj == 3)
jj = 0;
else
jj++;
}
break;
}
if (forward.at(j) == 'W') {
if (t3 == 'S')
y--;
else if (t3 == 'E')
x++;
else if (t3 == 'W')
x--;
else
y++;
x11.push_back(x);
y11.push_back(y);
}
if (forward.size() - 1 != j)
if (forward.at(j + 1) == 'W') {
n.push_back(M['N']);
e.push_back(M['E']);
s.push_back(M['S']);
w.push_back(M['W']);
M['N'] = 0;
M['E'] = 0;
M['S'] = 0;
M['W'] = 0;
}
if (forward.size() - 1 == j) {
n.push_back(M['N']);
e.push_back(M['E']);
s.push_back(M['S']);
w.push_back(M['W']);
x22 = x;
y22 = y;
}
}
M['N'] = 0;
M['E'] = 0;
M['S'] = 0;
M['W'] = 0;
if (jj == 2)
jj = 0;
else if (jj == 3)
jj = 1;
else
jj = jj + 2;
for (j = 0; j < reverse.size(); j++) {
current = reverse.at(j);
t1 = x1[jj];
t2 = x2[jj];
t3 = x3[jj];
t4 = x4[jj];
switch (current) {
case 'W':
M[t1] = 1;
break;
case 'L':
M[t2] = 1;
if (jj == 0)
jj = 3;
else
jj--;
break;
case 'R':
if (reverse.size() - 1 != j)
if (reverse.at(j + 1) == 'R') {
M[t1] = 1;
M[t2] = 0;
M[t3] = 0;
M[t4] = 0;
j++;
if (jj == 2)
jj = 0;
else if (jj == 3)
jj = 1;
else
jj = jj + 2;
}
else {
M[t1] = 1;
M[t2] = 0;
M[t3] = 0;
M[t4] = 1;
if (jj == 3)
jj = 0;
else
jj++;
}
break;
}
if (reverse.at(j) == 'W') {
if (t3 == 'S')
y--;
else if (t3 == 'E')
x++;
else if (t3 == 'W')
x--;
else
y++;
x11.push_back(x);
y11.push_back(y);
}
if (reverse.size() - 1 != j)
if (reverse.at(j + 1) == 'W') {
n.push_back(M['N']);
e.push_back(M['E']);
s.push_back(M['S']);
w.push_back(M['W']);
M['N'] = 0;
M['E'] = 0;
M['S'] = 0;
M['W'] = 0;
}
if (reverse.size() - 1 == j) {
n.push_back(M['N']);
e.push_back(M['E']);
s.push_back(M['S']);
w.push_back(M['W']);
}
}
for (int i = 0; i < x11.size(); i++)
if (x11[i] == x22 && y11[i] == y22) {
x11.erase(x11.begin() + i);
y11.erase(y11.begin() + i);
n.erase(n.begin() + i);
e.erase(e.begin() + i);
s.erase(s.begin() + i);
w.erase(w.begin() + i);
}
int yy = x11.size() - 1;
x11.erase(x11.begin() + yy);
y11.erase(y11.begin() + yy);
n.erase(n.begin() + yy);
e.erase(e.begin() + yy);
s.erase(s.begin() + yy);
w.erase(w.begin() + yy);
for (i = 0; i < x11.size(); i++)
for (j = 0; j < x11.size(); j++)
if (x11[i] == x11[j] && y11[i] == y11[j] && i != j) {
n[i] = n[i] | n[j];
e[i] = e[i] | e[j];
s[i] = s[i] | s[j];
w[i] = w[i] | w[j];
x11.erase(x11.begin() + j);
y11.erase(y11.begin() + j);
n.erase(n.begin() + j);
e.erase(e.begin() + j);
s.erase(s.begin() + j);
w.erase(w.begin() + j);
}
maxx = *max_element(x11.begin(), x11.end());
maxy = *max_element(y11.begin(), y11.end());
minx = *min_element(x11.begin(), x11.end());
miny = *min_element(y11.begin(), y11.end());
v1 = (-minx);
v2 = (maxy);
for (i = 0; i < x11.size(); i++)
x11[i] = x11[i] + v1;
for (j = 0; j < y11.size(); j++)
y11[j] = (-y11[j]) + v2;
maxx = *max_element(x11.begin(), x11.end());
maxy = *max_element(y11.begin(), y11.end());
for (l = 0; l <= maxy; l++)
for (ll = 0; ll <= maxx; ll++)
for (i = 0; i < n.size(); i++)
if (x11[i] == ll && y11[i] == l) {
n1[tt] = n[i];
e1[tt] = e[i];
s1[tt] = s[i];
w1[tt] = w[i];
tt++;
}
for (l = 0; l < n.size(); l++) {
lt[l] = (w1[l] * 100) + (s1[l] * 10) + (e1[l] * 1000) + n1[l];
}
cout << "case#" << kk + 1 << ":";
for (l = 0; l < n.size(); l++) {
if (l % (maxx + 1) == 0)
cout << endl;
if (lt[l] == 1)
cout << "1";
else if (lt[l] == 10)
cout << "2";
else if (lt[l] == 11)
cout << "3";
else if (lt[l] == 100)
cout << "4";
else if (lt[l] == 101)
cout << "5";
else if (lt[l] == 110)
cout << "6";
else if (lt[l] == 111)
cout << "7";
else if (lt[l] == 1000)
cout << "8";
else if (lt[l] == 1001)
cout << "9";
else if (lt[l] == 1010)
cout << "a";
else if (lt[l] == 1011)
cout << "b";
else if (lt[l] == 1100)
cout << "c";
else if (lt[l] == 1101)
cout << "d";
else if (lt[l] == 1110)
cout << "e";
if (lt[l] == 1111)
cout << "f";
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment