Advertisement
Mirbek

ТЫНЫСТАНОВ

Jan 18th, 2022
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. char ch[] = {'A', 'E', 'I', 'O', 'o', 'U', 'u', 'Y'};
  6. map<char, char> nxt;
  7. vector <string> dictionary;
  8.  
  9. void brute(string t) {
  10.     if (t.size() == 5) {
  11.         dictionary.push_back(t);
  12.         return;
  13.     }
  14.     if (t.empty()) {
  15.         for (int i = 0; i < 8; i++) {
  16.             brute(t + ch[i]);
  17.         }
  18.         return;
  19.     }
  20.     brute(t + t.back());
  21.     brute(t + nxt[t.back()]);
  22. }
  23.  
  24. int getPos(char c) {
  25.     for (int i = 0; i < 8; i++) {
  26.         if (ch[i] == c) return i;
  27.     }
  28. }
  29.  
  30. bool cmp(string a, string b) {
  31.     for (int i = 0; i < a.size(); i++) {
  32.         int x = getPos(a[i]);
  33.         int y = getPos(b[i]);
  34.         if (x == y) continue;
  35.         return x < y;
  36.     }
  37.     return 0;
  38. }
  39.  
  40. int main(){
  41.     ios::sync_with_stdio(0);
  42.  
  43.     nxt['A'] = 'Y';
  44.     nxt['E'] = 'I';
  45.     nxt['I'] = 'E';
  46.     nxt['O'] = 'U';
  47.     nxt['o'] = 'u';
  48.     nxt['U'] = 'A';
  49.     nxt['u'] = 'o';
  50.     nxt['Y'] = 'A';
  51.  
  52.     brute("");
  53.  
  54.     sort(dictionary.begin(), dictionary.end(), cmp);
  55.  
  56.     string s;
  57.     cin >> s;
  58.  
  59.     for (int i = 0; i < dictionary.size(); i++) {
  60.         if (dictionary[i] == s) {
  61.             cout << dictionary[i + 1] << endl;
  62.             return 0;
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement