Advertisement
Guest User

kursachB #29

a guest
Mar 27th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. /*Вводится последовательность, состоящая из N пар символов (ai,bi). Каждая пара определяет порядок предшествования символов, например, пара (b,с) означает, что символ "b" предшествует символу "с". Из порядка (b,с) и (с,a) следует порядок (b,a). Необходимо определить, является ли введенная последовательность:
  2. а) полной, т.е. все использованные для формирования пар символы (выбросив повторяющиеся) можно выстроить в цепочку (A1,A2,...,As) в порядке предшествования;
  3. б) противоречивой, т.е. для некоторых символов x,y можно получить одновременно порядок как (x,y) так и (y,x);
  4. в) неполной и непротиворечивой.*/
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. using namespace std;
  9. bool check(vector<string> a)
  10. {
  11.     bool flag;
  12.     for (int i = 0; i < a.size() - 1; i++)
  13.     {
  14.         flag = false;
  15.         if (a[i][1] == a[i + 1][0])
  16.             flag = true;
  17.     }
  18.     return flag;
  19. }
  20. bool checkbut(vector<string> a)
  21. {
  22.     bool flagbut=false;
  23.     for (int i = 0; i < a.size() - 1; i++)
  24.     {
  25.         if (a[i][1] == a[i + 1][0] && a[i][0]==a[i+1][1])
  26.             flagbut = true;
  27.     }
  28.     return flagbut;
  29. }
  30. void func(vector<string> b, bool t, bool e)
  31. {
  32.     string str1, str2;
  33.     if (t == true && e == true)
  34.     {
  35.         for (int i = 0; i < b.size(); ++i)
  36.         for (int j = 0; j < b[i].size(); ++j)
  37.             str1.push_back(b[i][j]);
  38.         for (int a = 0; a < str1.size(); a++)
  39.         {
  40.             if (str2.find(str1[a]) == -1)
  41.                 str2.push_back(str1[a]);
  42.         }
  43.         cout << "Sequence is contradictory: " << str2 << endl;
  44.         t = false; return;
  45.     }
  46.     if (t == true)
  47.     {
  48.         for (int i = 0; i < b.size(); ++i)
  49.         for (int j = 0; j < b[i].size(); ++j)
  50.             str1.push_back(b[i][j]);
  51.         for (int a = 0; a < str1.size(); a++)
  52.         {
  53.             if (str2.find(str1[a]) == -1)
  54.                 str2.push_back(str1[a]);
  55.         }
  56.         cout << "Sequence is complete : " << str2 << endl;
  57.     }
  58.     else cout << "Sequence is noncontradictory." << endl;
  59. }
  60. void main()
  61. {
  62.     int sizeofstr;
  63.     cout << "Enter the count of pairs: ";
  64.     cin >> sizeofstr;
  65.     if (sizeofstr <= 1)
  66.     {
  67.         cout << "The size less or equal 1.Error!\nPress any key exit."; cin.get();cin.get(); exit(0);
  68.     }
  69.     vector<string> temp(sizeofstr);
  70.     cout << "Enter the pairs of symbols" << endl;
  71.     for (int i = 0; i < sizeofstr; ++i)
  72.     {
  73.         cout << "Pair #" << i + 1 << ": ";
  74.         cin >> temp[i];
  75.         if (temp[i].size()>2)
  76.         {
  77.             cout << "You entered more than 2 symbol.Error!" << endl; break;
  78.         }
  79.     }
  80.     cout << "Entered symbols: ";
  81.     for (int i = 0; i < sizeofstr; ++i)
  82.     cout << temp[i];
  83.     cout << endl;
  84.     func(temp, check(temp),checkbut(temp));
  85.     system("pause");
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement