Загрузка данных
#include <iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
int F;
int first;
// ==========================================
// ТАБЛИЦА ИСТИННОСТИ + ЭЛЕМЕНТЫ СДНФ/СКНФ
// ==========================================
cout << "a b c d e | F | SDNF / SKNF" << endl;
cout << "---------------------------------------------" << endl;
for (a = 0; a <= 1; a++)
{
for (b = 0; b <= 1; b++)
{
for (c = 0; c <= 1; c++)
{
for (d = 0; d <= 1; d++)
{
for (e = 0; e <= 1; e++)
{
F = (a || !b || !c) && (d || !e);
cout << a << " "
<< b << " "
<< c << " "
<< d << " "
<< e << " | "
<< F << " | ";
// -------------------------
// Если F = 1 -> СДНФ
// -------------------------
if (F == 1)
{
cout << "SDNF: (";
if (a == 0)
cout << "!a";
else
cout << "a";
cout << " && ";
if (b == 0)
cout << "!b";
else
cout << "b";
cout << " && ";
if (c == 0)
cout << "!c";
else
cout << "c";
cout << " && ";
if (d == 0)
cout << "!d";
else
cout << "d";
cout << " && ";
if (e == 0)
cout << "!e";
else
cout << "e";
cout << ")";
}
// -------------------------
// Если F = 0 -> СКНФ
// -------------------------
if (F == 0)
{
cout << "SKNF: (";
if (a == 0)
cout << "a";
else
cout << "!a";
cout << " || ";
if (b == 0)
cout << "b";
else
cout << "!b";
cout << " || ";
if (c == 0)
cout << "c";
else
cout << "!c";
cout << " || ";
if (d == 0)
cout << "d";
else
cout << "!d";
cout << " || ";
if (e == 0)
cout << "e";
else
cout << "!e";
cout << ")";
}
cout << endl;
}
}
}
}
}
// ==========================================
// ПОЛНАЯ СДНФ
// ==========================================
cout << endl;
cout << "SDNF:" << endl;
first = 1;
for (a = 0; a <= 1; a++)
{
for (b = 0; b <= 1; b++)
{
for (c = 0; c <= 1; c++)
{
for (d = 0; d <= 1; d++)
{
for (e = 0; e <= 1; e++)
{
F = (a || !b || !c) && (d || !e);
if (F == 1)
{
if (first == 0)
cout << " || ";
cout << "(";
if (a == 0)
cout << "!a";
else
cout << "a";
cout << " && ";
if (b == 0)
cout << "!b";
else
cout << "b";
cout << " && ";
if (c == 0)
cout << "!c";
else
cout << "c";
cout << " && ";
if (d == 0)
cout << "!d";
else
cout << "d";
cout << " && ";
if (e == 0)
cout << "!e";
else
cout << "e";
cout << ")";
first = 0;
}
}
}
}
}
}
// ==========================================
// ПОЛНАЯ СКНФ
// ==========================================
cout << endl << endl;
cout << "SKNF:" << endl;
first = 1;
for (a = 0; a <= 1; a++)
{
for (b = 0; b <= 1; b++)
{
for (c = 0; c <= 1; c++)
{
for (d = 0; d <= 1; d++)
{
for (e = 0; e <= 1; e++)
{
F = (a || !b || !c) && (d || !e);
if (F == 0)
{
if (first == 0)
cout << " && ";
cout << "(";
if (a == 0)
cout << "a";
else
cout << "!a";
cout << " || ";
if (b == 0)
cout << "b";
else
cout << "!b";
cout << " || ";
if (c == 0)
cout << "c";
else
cout << "!c";
cout << " || ";
if (d == 0)
cout << "d";
else
cout << "!d";
cout << " || ";
if (e == 0)
cout << "e";
else
cout << "!e";
cout << ")";
first = 0;
}
}
}
}
}
}
cout << endl;
return 0;
}