|
@@ -1,5 +1,6 @@
|
|
|
#include <cstdio>
|
|
|
#include <cstdlib>
|
|
|
+#include <cstring>
|
|
|
#include <queue>
|
|
|
|
|
|
using std::priority_queue;
|
|
@@ -77,7 +78,7 @@ int next_state(int p, char m) {
|
|
|
bool even_perm(int s) {
|
|
|
char perm[10];
|
|
|
sprintf(perm, "%09d", s);
|
|
|
- int cnt = 0; // 0 is not included
|
|
|
+ int cnt = 0; // 0 is not included
|
|
|
for (int i = 1; i < 9; i++) {
|
|
|
if (perm[i] == '0') continue;
|
|
|
for (int j = 0; j < i; j++)
|
|
@@ -141,21 +142,25 @@ bool a_star(int s) {
|
|
|
|
|
|
int main() {
|
|
|
char perm[10];
|
|
|
- for (int i = 0; i < 9; i++) {
|
|
|
- scanf("%s", &perm[i]);
|
|
|
- if (perm[i] == 'x') perm[i] = '0';
|
|
|
- }
|
|
|
- int src = atoi(perm);
|
|
|
- if (a_star(src)) {
|
|
|
- int pos = perm2no(dst), i = 0;
|
|
|
- do {
|
|
|
- res[i++] = close[pos].m;
|
|
|
- pos = perm2no(close[pos].p);
|
|
|
- } while (pos != -1); // The (i-1)th char is 0! So i - 2
|
|
|
- for (int j = i - 2; 0 <= j; j--) printf("%c", res[j]);
|
|
|
- printf("\n");
|
|
|
- } else {
|
|
|
- printf("unsolvable\n");
|
|
|
+ while (scanf("%s", &perm[0]) != EOF) {
|
|
|
+ if (perm[0] == 'x') perm[0] = '0';
|
|
|
+ for (int i = 1; i < 9; i++) {
|
|
|
+ scanf("%s", &perm[i]);
|
|
|
+ if (perm[i] == 'x') perm[i] = '0';
|
|
|
+ }
|
|
|
+ memset(close, 0, sizeof(close));
|
|
|
+ int src = atoi(perm);
|
|
|
+ if (a_star(src)) {
|
|
|
+ int pos = perm2no(dst), i = 0;
|
|
|
+ do {
|
|
|
+ res[i++] = close[pos].m;
|
|
|
+ pos = perm2no(close[pos].p);
|
|
|
+ } while (pos != -1); // The (i-1)th char is 0! So i - 2
|
|
|
+ for (int j = i - 2; 0 <= j; j--) printf("%c", res[j]);
|
|
|
+ printf("\n");
|
|
|
+ } else {
|
|
|
+ printf("unsolvable\n");
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|