|
#include <stdio.h> #include <string.h>
char map[26], rev_map[26], res[26]; int N, pre[26];
void dfs(int idx, int used) { int i;
if (idx == N) { for (i = 0; i < N; i++) printf("%c", map[res[i]] + 'a'); printf("\n"); return ; }
for (i = 0; i < N; i++) { if (used & (1 << i)) continue; if ((pre[i] & used) != pre[i]) continue; res[idx] = i; dfs(idx + 1, used | (1 << i)); } }
int main() { char a, b; int i;
freopen("e:\\test\\in.txt", "r", stdin);
while (1) {
memset(rev_map, 0, sizeof(rev_map)); while (1) { a = getchar(); if (a == EOF) return 0; if (a == '\n') break; if (a >= 'a' && a <= 'z') rev_map[a - 'a'] = 1; } for (i = N = 0; i < 26; i++) if (rev_map[i]) { map[N] = i; rev_map[i] = N++; }
memset(pre, 0, sizeof(pre)); i = 0; while (1) { a = getchar(); if (a == '\n' || a == EOF) break; if (a < 'a' || a > 'z') continue; if (i & 1) pre[rev_map[a - 'a']] |= 1 << rev_map[b - 'a']; else b = a; i++; }
dfs(0, 0); printf("\n"); }
return 0; }
|