Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

來源:互聯網
上載者:User

標籤:

原題地址: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 100005using 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;}

 

Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.