Дано целое число. Если оно является положительным, то прибавить к нему 1; если отрицательным, то вычесть из него 2; если нулевым, то заменить его на 10. Вывести полученное число.
// 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) // вывод максимальной длины серии в файл. Конец программы
a = int(input())
if a > 0:
a = a + 1
elif a < 0:
a = a - 2
else:
a = 10
print(a)
Если программу надо написать как на блок-схеме, то тогда вот так.
a = int(input())
if a >= 0:
if a == 0:
a = 10
else:
a = a + 1
else:
a = a - 2
print(a)