Advertisement
mihaimarcel21

Bacon

Feb 17th, 2021
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("bacon.in");
  5. ofstream fout("bacon.out");
  6. int C;
  7. char mess[50005], ha[6];
  8. char *codes[] = {
  9.     "AAAAA", "AAAAB", "AAABA", "AAABB", "AABAA",
  10.     "AABAB", "AABBA", "AABBB", "ABAAA", "ABAAB",
  11.     "ABABA", "ABABB", "ABBAA", "ABBAB", "ABBBA",
  12.     "ABBBB", "BAAAA", "BAAAB", "BAABA", "BAABB",
  13.     "BABAA", "BABAB", "BABBA", "BABBB", "BBAAA",
  14.     "BBAAB", "BBBAA"
  15. };
  16. char get_char(const char *code)
  17. {
  18.     int i;
  19.     for (i = 0; i < 26; ++i)
  20.     {
  21.         if (strcmp(codes[i], code) == 0) return 97 + i;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     fin>>C;
  28.     fin>>mess;
  29.     if(C==1)
  30.     {
  31.         for(int i=0; mess[i]; i++)
  32.             fout<<codes[mess[i]-'A'];
  33.     }
  34.     else
  35.     {
  36.         int j=0, i=0;
  37.         while(mess[i])
  38.         {
  39.             for(int j=0; j<5; j++)
  40.                 ha[j]=mess[i++];
  41.             ha[5]='\0';
  42.             fout<<((char)toupper(get_char(ha)));
  43.         }
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement