Решите таблицу истинности с логической функцией F (см. рис) 1)Логическая функция F задается выражением (x/\-y) v (x ~ z) v w Дан частично заполненный фрагмент таблицы истинности, содержащей неповторяющиеся строки таблицы истинности F. Определите, какому столбцу таблицы соответствует каждая из переменных х, у, z, w. В ответе напишите буквы w, х, y, z в том порядке, в котором идут соответствующие им столбцы
2) Миша заполнял таблицу истинности логической функции F -(y = (x ~ w)) /\ (z = x), но успел заполнить лишь фрагмент из трёх различных её строк, даже не указав, какому столбцу таблицы соответствует каждая из переменных w, x, y, z. Определите, какому столбцу таблицы соответствует каждая из переменных w, х, у, z.
ps: /\ - и, v - или, - - не, = - если то, ~ - если и только.
// PascalABC.NET 3.1, сборка 1204 от 24.03.2016 begin var F,G:file of integer; Assign(F,'FFile.dat'); Rewrite(F); for var i:=1 to 30 do Write(F,Random(-20,20)); // Файл F создан и заполнен Assign(G,'GFile.dat'); Rewrite(G); F.Seek(0); var e:integer; Print('F:'); while not F.Eof do begin Read(F,e); Print(e); if e>0 then Write(G,e) end; F.Seek(0); while not F.Eof do begin Read(F,e); if e<0 then Write(G,e) end; F.Seek(0); while not F.Eof do begin Read(F,e); if e=0 then Write(G,e) end; F.Close; Writeln; Print('G:'); G.Seek(0); while not G.Eof do begin Read(G,e); Print(e) end; G.Close end.
Данное решение неоптимально по времени, поскольку файл читается трижды. Можно сделать иной вариант, читая данные за один проход и помещая в две вс структуры памяти отрицательные и нулевые элементы.
// PascalABC.NET 3.1, сборка 1204 от 24.03.2016 begin var F,G:file of integer; Assign(F,'FFile.dat'); Rewrite(F); for var i:=1 to 30 do Write(F,Random(-20,20)); // Файл F создан и заполнен Assign(G,'GFile.dat'); Rewrite(G); var n:=F.FileSize; var neg,zer:array of integer; SetLength(neg,n); SetLength(zer,n); F.Seek(0); var e:integer; var ineg:=0; var izer:=0; Print('F:'); while not F.Eof do begin Read(F,e); Print(e); if e>0 then Write(G,e) else if e<0 then begin neg[ineg]:=e; Inc(ineg) end else begin zer[izer]:=e; Inc(izer) end end; F.Close; Writeln; SetLength(neg,ineg); foreach e in neg do Write(G,e); SetLength(zer,izer); foreach e in zer do Write(G,e); Print('G:'); G.Seek(0); while not G.Eof do begin Read(G,e); Print(e) end; G.Close end.
Суть программы Input (A[255], input.txt); // Вводим из файла строку в массив А[255] N = 0; NMax = 0; // Счетчик удачных дней M = 0; // Счетчик длины массива (он может быть и меньше 255) Цикл по i от 1 до 255 If (A[i] <> "У") and (A[i] <> "Н") then M = i - 1; // Как только мы встретили значение, не равное ни У ни Н, так считаем это концом. Конец цикла по i If A[1] = "У" then N = 1 // Проверяем 1-ую ячейку Цикл по i от 1 до M-1 if (A[i] = "Н") and (A[i+1] = "У") then N = 1; // Начало серии У if (A[i] = "У") and (A[i+1] = "У") then N = N + 1; // Продолжение серии У if (A[i] = "У") and (A[i+1] = "Н") then // Окончание серии У if N >= NMax then NMax = N; // Проверяем длину серии end if Конец Цикла по i Output (output.txt, NMax) // вывод максимальной длины серии в файл. Конец программы
begin
var F,G:file of integer;
Assign(F,'FFile.dat'); Rewrite(F);
for var i:=1 to 30 do Write(F,Random(-20,20));
// Файл F создан и заполнен
Assign(G,'GFile.dat'); Rewrite(G);
F.Seek(0);
var e:integer;
Print('F:');
while not F.Eof do begin
Read(F,e); Print(e);
if e>0 then Write(G,e)
end;
F.Seek(0);
while not F.Eof do begin
Read(F,e);
if e<0 then Write(G,e)
end;
F.Seek(0);
while not F.Eof do begin
Read(F,e);
if e=0 then Write(G,e)
end;
F.Close;
Writeln;
Print('G:');
G.Seek(0);
while not G.Eof do begin
Read(G,e); Print(e)
end;
G.Close
end.
Тестовое решение:
F: -14 15 -16 0 7 0 18 19 -12 -10 6 15 -19 -14 -15 -1 -6 -4 -20 12 10 4 3 16 -14 -20 3 10 -13 -16
G: 15 7 18 19 6 15 12 10 4 3 16 3 10 -14 -16 -12 -10 -19 -14 -15 -1 -6 -4 -20 -14 -20 -13 -16 0 0
Данное решение неоптимально по времени, поскольку файл читается трижды. Можно сделать иной вариант, читая данные за один проход и помещая в две вс структуры памяти отрицательные и нулевые элементы.
// PascalABC.NET 3.1, сборка 1204 от 24.03.2016
begin
var F,G:file of integer;
Assign(F,'FFile.dat'); Rewrite(F);
for var i:=1 to 30 do Write(F,Random(-20,20));
// Файл F создан и заполнен
Assign(G,'GFile.dat'); Rewrite(G);
var n:=F.FileSize;
var neg,zer:array of integer;
SetLength(neg,n); SetLength(zer,n);
F.Seek(0);
var e:integer;
var ineg:=0;
var izer:=0;
Print('F:');
while not F.Eof do begin
Read(F,e); Print(e);
if e>0 then Write(G,e)
else
if e<0 then begin neg[ineg]:=e; Inc(ineg) end
else begin zer[izer]:=e; Inc(izer) end
end;
F.Close;
Writeln;
SetLength(neg,ineg);
foreach e in neg do Write(G,e);
SetLength(zer,izer);
foreach e in zer do Write(G,e);
Print('G:');
G.Seek(0);
while not G.Eof do begin
Read(G,e); Print(e)
end;
G.Close
end.
Тестовое решение:
F: 7 5 -14 6 -11 -9 5 -1 5 -5 -7 -1 4 -20 17 -19 0 -3 0 6 20 1 -2 -18 9 20 0 -2 3 -13
G: 7 5 6 5 5 4 17 6 20 1 9 20 3 -14 -11 -9 -1 -5 -7 -1 -20 -19 -3 -2 -18 -2 -13 0 0 0