题目
#include <cstdio>
#include <iostream>
#include <map>
#include <cstring>
#include <string>
using namespace std;
const int N = 4e6 + 10;
string x[N];
int step[N][3];
int hh, tt;
string x1;
map <string, int> m;
map<string, int>::iterator kk;
string ans;
void add (string s, int ff, int b) {
m[s] = tt;
step[tt][0] = ff;
step[tt][1] = step[ff][1] + 1;
step[tt][2] = b;
x[tt ++] = s;
}
void print (int cnt) {
for (int i = cnt; step[i][2] != 0; i = step[i][0]) {
if (step[i][2] == 1) ans += 'A';
else if (step[i][2] == 2) ans += 'B';
else ans += 'C';
}
}
void bfs () {
hh = tt = 1;
add ("12348765", 0, 0);
while (hh < tt) {
string sh = x[hh ++];
if (sh == x1) {
printf ("%d\n", step[hh - 1][1] - 1);
print (hh - 1);
for (int i = step[hh - 1][1] - 2; i >= 0; i -- ) printf ("%c", ans[i]);
return;
}
string s1, s2, s3;
for (int i = 4; i < 8; i ++ ) s1 += sh[i];
for (int i = 0; i < 4; i ++ ) s1 += sh[i];
s2 += sh[3];
for (int i = 0; i < 3; i ++ ) s2 += sh[i];
s2 += sh[7];
for (int i = 4; i < 7; i ++ ) s2 += sh[i];
s3 = sh; s3[1] = sh[5], s3[2] = sh[1], s3[6] = sh[2], s3[5] = sh[6];
if (m.find(s1) == m.end ()) add (s1, hh - 1, 1);
if (m.find(s2) == m.end ()) add (s2, hh - 1, 2);
if (m.find(s3) == m.end ()) add (s3, hh - 1, 3);
}
}
int main () {
char c;
for (int i = 0; i < 8; i ++ ) {
scanf (" %c", &c);
x1 += c;
}
bfs ();
return 0;
}