Список с 201 элементом (от -100 до 100):
a = [i for i in range(-100,101)]
b = []
c = []
for value in a:
if value < 0: b.append(value)
if value > 0: c.append(value)
print(*a)
print()
print(*b)
print()
print(*c)
То же, но через лямбда-функции:
a = [i for i in range(-100,101)]
print(*a)
print()
print(*list(filter(lambda x: x<0, a)))
print()
print(*list(filter(lambda x: x>0, a)))
Список с рандомными элементами величиной 100:
from random import randint
a = [randint(-100,100) for _ in range(100)]
b = []
c = []
for value in a:
if value < 0: b.append(value)
if value > 0: c.append(value)
print(*a)
print()
print(*b)
print()
print(*c)
#include <iostream>
using namespace std;
void hanoi_towers(int quantity, int from, int to, int buf_peg) //quantity-число колец, from-начальное положение колец(1-3),to-конечное положение колец(1-3)
{ //buf_peg - промежуточный колышек(1-3)
if (quantity != 0)
{
hanoi_towers(quantity-1, from, buf_peg, to);
cout << from << " -> " << to << endl;
hanoi_towers(quantity-1, buf_peg, to, from);
}
}
int main()
{
setlocale(LC_ALL,"rus");
int start_peg, destination_peg, buffer_peg, plate_quantity;
cout << "Номер первого столбика:" << endl;
cin >> start_peg;
cout << "Номер конечного столбика:" << endl;
cin >> destination_peg;
cout << "Номер промежуточного столбика:" << endl;
cin >> buffer_peg;
cout << "Количество дисков:" << endl;
cin >> plate_quantity;
hanoi_towers(plate_quantity, start_peg, destination_peg, buffer_peg);
return 0;
}
Объяснение:
Free Pascal
var
s, a : string;
i, p:integer;
begin
writeln('Введите строку:');
readln(s);
writeln('Введите удаляемый символ(ы):');
readln(a);
p:=pos(a, s);
while p > 0 do begin
delete(s, p, length(a));
p:=pos(a, s);
end;
writeln(s);
end.