#include #include #include #include using namespace std; typedef pair Pair; set relation; set elements; void inputRelation() { string line; while (getline(cin, line)) { if (line == "end") break; istringstream iss(line); string a, b; if (!(iss >> a >> b)) { cout << "Ошибка ввода: " << line << endl; continue; } relation.insert({a, b}); elements.insert(a); elements.insert(b); } } bool isReflexive() { for (const string& x : elements) { if (relation.find({x, x}) == relation.end()) { return false; } } return true; } bool isSymmetric() { for (const Pair& p : relation) { if (relation.find({p.second, p.first}) == relation.end()) { // проходимся по всем парам и ищем хотя бы однк не по условию return false; } } return true; } bool isAntisymmetric() { for (const Pair& p : relation) { if (p.first != p.second) { // a!=b и есть пара if (relation.find({p.second, p.first}) != relation.end()) { return false; } } } return true; } bool isTransitive() { for (const Pair& p1 : relation) { for (const Pair& p2 : relation) { if (p1.second == p2.first) { Pair trans = {p1.first, p2.second}; // цикл вложенных пар if (relation.find(trans) == relation.end()) { return false; } } } } return true; } int main() { cout << "Пары элементов отношения:\n"; inputRelation(); cout << "Рефлексивность: " << (isReflexive() ? "Да" : "Нет") << endl; cout << "Симметричность: " << (isSymmetric() ? "Да" : "Нет") << endl; cout << "Кососимметричность: " << (isAntisymmetric() ? "Да" : "Нет") << endl; cout << "Транзитивность: " << (isTransitive() ? "Да" : "Нет") << endl; cout << "Эквивалентность: " << ((isTransitive() and isReflexive() and isSymmetric()) ? "Да" : "Нет") << endl; cout << "Частичный порядок: " << ((isTransitive() and isReflexive() and isAntisymmetric()) ? "Да" : "Нет") << endl; return 0; }