原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-european-regional-contest-neerc-08-en.pdf
此题题意是给你一个单对单密文,让你还原为原文,原文有个性质是,每个单词都是元音和辅音交替组成。
做法是直接5重for,暴力枚举AEIOU分别对应的字母,然后检查,然后输出
详见代码:
//#include<iostream> #include<fstream> #include<vector> #include<string> #include <string.h> #define MAX_A 26 #define MAX_N 100005 using namespace std; vector<int> G[MAX_A]; string str[MAX_N]; int n = 0; string s; bool g[MAX_A][MAX_A]; int vo[MAX_A]; int tot = 0; bool flag = 1; int main() { ifstream cin("javanese.in"); ofstream cout("javanese.out"); cin.sync_with_stdio(false); for (int i = 0; i < 26; i++) { if (i != 0 && i != ‘E‘ - ‘A‘ && i != ‘I‘ - ‘A‘ && i != ‘O‘ - ‘A‘ && i != ‘U‘ - ‘A‘) vo[tot++] = i; } while (cin >> s) { if (s == "*")break; str[n++] = s; for (int i = 0; i + 1 < s.length(); i++) { int u = s[i] - ‘A‘, v = s[i + 1] - ‘A‘; if (u == v)flag = false; if (g[u][v])continue; G[s[i] - ‘A‘].push_back(s[i + 1] - ‘A‘); g[u][v] = 1; } if (flag == 0) { cout << "impossible" << endl; return 0; } } int a[5]; for (a[0] = 0; a[0] < 26; a[0]++) for (a[1] = a[0] + 1; a[1] < 26; a[1]++) for (a[2] = a[1] + 1; a[2] < 26; a[2]++) for (a[3] = a[2] + 1; a[3] < 26; a[3]++) for (a[4] = a[3] + 1; a[4] < 26; a[4]++) { int f[26]; memset(f, -1, sizeof(f)); int tmp = 0; bool t = 1; for (int i = 0; i < 5 && t; i++) for (int j = 0; j < 5 && t; j++)if (g[a[i]][a[j]])t = 0; if (t == 0)continue; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) if (g[i][j] && i != a[0] && i != a[1] && i != a[2] && i != a[3] && i != a[4] && j != a[0] && j != a[1] && j != a[2] && j != a[3] && j != a[4]) t = 0; if (t == 0)continue; for (int i = 0; i < n; i++, cout << " ") for (int j = 0; j < str[i].length(); j++) { int u = str[i][j] - ‘A‘; if (f[u] != -1) { cout << (char)(f[u] + ‘A‘); continue; } if (u == a[0])f[u] = ‘A‘ - ‘A‘; else if (u == a[1])f[u] = ‘E‘ - ‘A‘; else if (u == a[2])f[u] = ‘I‘ - ‘A‘; else if (u == a[3])f[u] = ‘O‘ - ‘A‘; else if (u == a[4])f[u] = ‘U‘ - ‘A‘; else f[u] = vo[tmp++]; cout << (char)(f[u] + ‘A‘); } cout << endl; return 0; } cout << "impossible" << endl; return 0; }
时间: 2024-12-22 09:17:25