ftpud12

Untitled

Nov 24th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #define _CTR_SECURE_NO_WARNINGS
  5.  
  6. const int PHRASE_LEN = 9;
  7.  
  8. using namespace std;
  9.  
  10. string table[2] = { "the quick brown fox jumps over the lazy dog", "" };
  11. char trans(char ch)
  12. {
  13.     for (int i = 0; table[0][i]; i++)
  14.     {
  15.         if (ch == table[1][i]) return table[0][i];
  16.     }
  17.  
  18.     return ch;
  19. }
  20.  
  21. int calcChars(string phrase, char ch) {
  22.     int c=0;
  23.     for(int i=0; phrase[i]; i++) {
  24.         if(phrase[i] == ch) {
  25.             c++;
  26.         }
  27.     }
  28.     return c;
  29. }
  30.  
  31. void ToDo()
  32. {
  33.     const char phrase[] = "\2\2\3 \1\2\1\1\1 \1\2\4\1\1 \1\4\1 \1\2\1\1\1 \4\1\3\2 \2\2\3 \1\1\1\1 \1\4\1";
  34.  
  35.     ifstream in("input.txt");
  36.     if (!in.is_open())
  37.     {
  38.         cout << "file not open";
  39.         return;
  40.     }
  41.     bool isExists = false;
  42.  
  43.     int n;
  44.     in >> n;
  45.  
  46.     char ** text = new char* [n];
  47.     in.ignore(255, '\n'); //. пропустили первую строку
  48.     for (int i = 0; i < n; i++)
  49.     {
  50.         text[i] = new char[80];
  51.         in.getline(text[i], 80);
  52.         if (text[i][strlen(text[i]) - 1] == '\r') text[i][strlen(text[i]) - 1] = 0;
  53.  
  54.         //if (strlen(text[i]) == strlen(phrase))
  55.         //{
  56.         if (isExists == false)
  57.         {
  58.             for (int j = 0; j < strlen(text[i]); j++)
  59.             {
  60.                 if (text[i][j] == ' ' && phrase[j] == ' ' ||
  61.                         (text[i][j] != ' ' && phrase[j] != ' '
  62.                           && phrase[j] == calcChars(text[i], text[i][j]))) {
  63.                         isExists = true;
  64.                 }
  65.                 else
  66.                 {
  67.                     isExists = false;
  68.                     break;
  69.                 }
  70.             }
  71.             if (isExists) table[1] = text[i];
  72.         }
  73.     }
  74.  
  75.     ofstream out("output.txt");
  76.  
  77.  
  78.     if (isExists)
  79.     {
  80.         for (int i = 0; i < n; i++)
  81.         {
  82.             for (int j = 0; j < strlen(text[i]); j++)
  83.             {
  84.                 out << trans(text[i][j]);
  85.             }
  86.             out << "\n";
  87.         }
  88.     }
  89.     else out << "No solution";
  90.  
  91.     out.close();
  92.     in.close();
  93. }
  94.  
  95. int main()
  96. {
  97.     ToDo();
  98.  
  99.     //system("pause");
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment