Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Вводится последовательность, состоящая из N пар символов (ai,bi). Каждая пара определяет порядок предшествования символов, например, пара (b,с) означает, что символ "b" предшествует символу "с". Из порядка (b,с) и (с,a) следует порядок (b,a). Необходимо определить, является ли введенная последовательность:
- а) полной, т.е. все использованные для формирования пар символы (выбросив повторяющиеся) можно выстроить в цепочку (A1,A2,...,As) в порядке предшествования;
- б) противоречивой, т.е. для некоторых символов x,y можно получить одновременно порядок как (x,y) так и (y,x);
- в) неполной и непротиворечивой.*/
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- bool check(vector<string> a)
- {
- bool flag;
- for (int i = 0; i < a.size() - 1; i++)
- {
- flag = false;
- if (a[i][1] == a[i + 1][0])
- flag = true;
- }
- return flag;
- }
- bool checkbut(vector<string> a)
- {
- bool flagbut=false;
- for (int i = 0; i < a.size() - 1; i++)
- {
- if (a[i][1] == a[i + 1][0] && a[i][0]==a[i+1][1])
- flagbut = true;
- }
- return flagbut;
- }
- void func(vector<string> b, bool t, bool e)
- {
- string str1, str2;
- if (t == true && e == true)
- {
- for (int i = 0; i < b.size(); ++i)
- for (int j = 0; j < b[i].size(); ++j)
- str1.push_back(b[i][j]);
- for (int a = 0; a < str1.size(); a++)
- {
- if (str2.find(str1[a]) == -1)
- str2.push_back(str1[a]);
- }
- cout << "Sequence is contradictory: " << str2 << endl;
- t = false; return;
- }
- if (t == true)
- {
- for (int i = 0; i < b.size(); ++i)
- for (int j = 0; j < b[i].size(); ++j)
- str1.push_back(b[i][j]);
- for (int a = 0; a < str1.size(); a++)
- {
- if (str2.find(str1[a]) == -1)
- str2.push_back(str1[a]);
- }
- cout << "Sequence is complete : " << str2 << endl;
- }
- else cout << "Sequence is noncontradictory." << endl;
- }
- void main()
- {
- int sizeofstr;
- cout << "Enter the count of pairs: ";
- cin >> sizeofstr;
- if (sizeofstr <= 1)
- {
- cout << "The size less or equal 1.Error!\nPress any key exit."; cin.get();cin.get(); exit(0);
- }
- vector<string> temp(sizeofstr);
- cout << "Enter the pairs of symbols" << endl;
- for (int i = 0; i < sizeofstr; ++i)
- {
- cout << "Pair #" << i + 1 << ": ";
- cin >> temp[i];
- if (temp[i].size()>2)
- {
- cout << "You entered more than 2 symbol.Error!" << endl; break;
- }
- }
- cout << "Entered symbols: ";
- for (int i = 0; i < sizeofstr; ++i)
- cout << temp[i];
- cout << endl;
- func(temp, check(temp),checkbut(temp));
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement