Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <string>
  5. #include <cctype>
  6. #include <map>
  7. #include <iomanip>
  8. #include <fstream>
  9.  
  10. using namespace std;
  11.  
  12. //string alph = "abcdefghijklmnopqrstuvwxyz0123456789.?!,;:-";
  13. string alph = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя0123456789.?!,;:-\'\"";
  14.  
  15. int main()
  16. {
  17.     setlocale(LC_CTYPE, "Russian");
  18.     ifstream in("input.txt");
  19.     ofstream out("output.txt");
  20.     string str;
  21.     map <string, unsigned char> map_table_first;
  22.     map <unsigned char, string> map_table_second;
  23.     string start = "000000";
  24.     for (int i = 0; i < (int)alph.size(); i++)
  25.     {
  26.         map_table_first[start] = (unsigned char)alph[i];
  27.         map_table_second[(unsigned char)alph[i]] = start;
  28.         if (i == (int)alph.size() - 1)
  29.             break;
  30.         for (int j = (int)start.size() - 1; j >= 0; j--)
  31.         {
  32.             if (start[j] == '0')
  33.             {
  34.                 start[j] = '1';
  35.                 break;
  36.             }
  37.             else
  38.                 start[j] = '0';
  39.         }
  40.     }
  41.     unsigned char c;
  42.     unsigned int A = 2;
  43.     //unsigned int A = 3;
  44.     unsigned int C = 7;
  45.     unsigned int x = 6;
  46.     //unsigned int x = 3;
  47.     unsigned int m = alph.size();
  48.     while (!in.eof())
  49.     {
  50.         {
  51.             getline(in, str);
  52.             for (int i = 0; i < (int)str.size(); i++)
  53.             {
  54.                 c = (unsigned char)str[i];
  55.                 c = tolower(c);
  56.                 if (c == ' ')
  57.                 {
  58.                     out << c;
  59.                     continue;
  60.                 }
  61.                 string s1 = map_table_second[c];
  62.                 string s2 = map_table_second[(unsigned char)alph[x]];
  63.                 string sum = "";
  64.                 for (int i = 0; i < (int)s1.size(); i++)
  65.                 {
  66.                     if (s1[i] == '1')
  67.                         sum += (s2[i] == '1' ? '0' : '1');
  68.                     else
  69.                         sum += (s2[i] == '0' ? '0' : '1');
  70.                 }
  71.                 if (sum > start)
  72.                     out << map_table_first[start];
  73.                 else
  74.                     out << map_table_first[sum];
  75.                 x = (A * x + C) % m;
  76.             }
  77.             out << endl;
  78.         }
  79.     }
  80.     in.close();
  81.     out.close();
  82.     system("pause");
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement