#Python 3.8.3
from typing import *
def FindFirstIndex(source: Iterable[Any], predicate: Callable[[Any], Any]):
for index, item in enumerate(source):
if (predicate(item)):
return index
def main():
arr = [1, 2, 3, 4, 5, -1, 2, -4]
firstOdd = FindFirstIndex(arr, lambda p: p % 2 != 0)
firstNegative = FindFirstIndex(arr, lambda p: p < 0)
arr[firstOdd], arr[firstNegative] = arr[firstNegative], arr[firstOdd]
print(arr)
if __name__ == '__main__':
main()
Объяснение:
#Python 3.8.3
from typing import *
def FindFirstIndex(source: Iterable[Any], predicate: Callable[[Any], Any]):
for index, item in enumerate(source):
if (predicate(item)):
return index
def main():
arr = [1, 2, 3, 4, 5, -1, 2, -4]
firstOdd = FindFirstIndex(arr, lambda p: p % 2 != 0)
firstNegative = FindFirstIndex(arr, lambda p: p < 0)
arr[firstOdd], arr[firstNegative] = arr[firstNegative], arr[firstOdd]
print(arr)
if __name__ == '__main__':
main()
Объяснение:
var
s: string;
i, count: integer;
begin
writeln('Vvedite stroky: ');
readln(s);
for i := 1 to length(s) - 2 do
if copy(s, i, 3) = 'abc' then
count := count + 1;
writeln('Kol-vo: ', count);
end.
2.
var
s1, s2: string;
i, len1, len2: integer;
begin
writeln('Vvedite stroky 1: ');
readln(s1);
writeln('Vvedite stroky 2: ');
readln(s2);
len1 := length(s1);
len2 := length(s2);
if len1 > len2 then writeln('1 stroka dlinnee')
else if len1 < len2 then writeln('2 stroka dlinnee')
else writeln('dlini strok ravnie')
end.
3.
var
s1, s2, s3: string;
begin
writeln('Vvedite stroky 1: ');
readln(s1);
writeln('Vvedite stroky 2: ');
readln(s2);
s3 := s1[1] + s1[2] + s2[1] + s2[2];
writeln('Novaja stroka: ', s3);
end.