середа, 23 жовтня 2019 р.

Орієнтовні розв'язки практичної роботи № 5  тренінгу Python

Розв'язки по 100 балів, крім F (10 балів)

А
n=int(input())

a=set(map(int,input().split()))

m=int(input())

b=set(map(int,input().split()))

print(sum(list(a & b)))

B
n=int(input())

a=set(map(int,input().split()))

m=int(input())

b=set(map(int,input().split()))

print(sum(list(a | b)))

C
n=int(input())

a=set(map(int,input().split()))

m=int(input())

b=set(map(int,input().split()))

k=int(input())

c=set(map(int,input().split()))

d = a | b
d = d - c
d = list(d)
d.sort()
print(*d)

D
s = input()

l = list(s)

a = set(l)

b = set()

for i in a:
    if l.count(i) > 1:
        b.add(i)

b = b - {' '}

b = sorted(list(b))

print(*b)

E
import sys
s = input()
s = s.lower()
l = list(s)
L = []
for i in range(len(l)-1):
    if l.count(l[i]) == 1:
        L.append(l[i])


print(*sorted(L), sep='')



F
t = int(input())

d = set()
for i in range(t):
    n, m = map(int, input().split())
    a = set(map(int,input().split()))
    b = set(map(int,input().split()))
    c = a & b
    d.add(len(c))

for x in d:
    print(x)

G
import sys
l=[]
while True:
    a=sys.stdin.readline()
    if not a:
        break
    else:
        l.append(int(a))
print(max(l) - min(l))


H
import sys
#l=[]
#slovo = ''
max_len = 0
while True:
    slovo = sys.stdin.readline()
    if not slovo:
        break
    else:
        #l.append(a)
        if len(slovo) > max_len:
            max_len = len(slovo)
            max_slovo = slovo
print(max_slovo)


I
fi=open('text.dat','r')
fo=open('text.sol','w')
s=fi.read()
sum_a = 0
for x in s:
    if x == 'a':
        sum_a += 1
print(sum_a, file=fo)
fi.close()
fo.close()



J
fi=open('numbers.in','r')
fo=open('numbers.out','w')
n = int(fi.readline())
l = list(fi.readline().split())
max_sum_csifr = 0

for x in l:
    suma_csifr_x = 0
    for csifra in x:
        suma_csifr_x += int(csifra)
    if suma_csifr_x > max_sum_csifr:
        max_sum_csifr = suma_csifr_x
        chislo_max_sum_csifr = int(x)
print(chislo_max_sum_csifr, file = fo)

fi.close()
fo.close()

2 коментарі: