/* File: 850.cpp Author: ACboy Date: 2010-3-30 Result: AC Descripition: UVa 850 Crypt Kicker II */ #include <iostream> using namespace std; char s[] = "the quick brown fox jumps over the lazy dog"; int vis[30]; char change[30]; // search the match string. int ifFind(char a[]) { int i; int len = strlen(a); memset(vis, 0, sizeof(vis)); int ok = 1; // count是用来标记出现过的字符的个数 //int count = 0; // 对a串中是字符的进行检测 for (i = 0; i < len; i++) if (isalpha(a[i])) { int temp = a[i] - 'a'; // 如果该字符没有出现过而在明文s中有相应的字符出现 // 之前一直WA就是因为没有检测是s[i]是否为字符。 if (!vis[temp] && isalpha(s[i])) { // 标记该字符出现过 vis[temp] = 1; // count++; // 记录替代字符 change[temp] = s[i]; } else { // 如果字符出现过而可以被不同的字符替代,则表明a串不是匹配串 if (change[temp] != s[i]) { ok = 0; break; } } } // 只有当被替代的字符数为26而其没有出现一个字符可以被两个以上字符替代的情况时,a才是匹配串。 //if (count == 26 && ok) return 1; if (ok) return 1; else return 0; } int main() { #ifndef ONLINE_JUDGE freopen("850.txt", "r", stdin); #endif int n; scanf("%d/n", &n); int k = 0; char str[110][90]; while (n--) { int c = 0; char temp[90]; while (gets(temp)) { if (strcmp(temp, "") == 0) { break; } else { strcpy(str[c++], temp); } } int i, j; int ok = 0; for (i = 0; i < c; i++) { if (strlen(str[i]) == strlen(s) && ifFind(str[i])) { ok = 1; break; } } if (ok) { for (i = 0; i < c; i++) { int len = strlen(str[i]); for (j = 0; j < len; j++) if (isalpha(str[i][j])) { int temp = str[i][j] - 'a'; str[i][j] = change[temp]; } } for (i = 0; i < c; i++) { cout << str[i] << endl; } } else { cout << "No solution." << endl; } if (n != 0) cout << endl; } return 0; }