Форум » Кодирование и декодирование информации » (№ 4199) задача 14 ошибка в ответе » Ответить

(№ 4199) задача 14 ошибка в ответе

StupNum: Ошибка в ответе. [pre2] import itertools l = [] c = 2 while True: l1 = [''.join(i) for i in itertools.product('еия', repeat=c) if i.count('е') < 3 and i.count('и') < 3 and i.count('я') < 3] l += l1 c += 1 if len(l1) == 0: break print(l) print(len(l)*3) [/pre2] Получаем список всех возможных комбинаций гласных букв в словах, затем умножаем его длину на три, т.к. на первом месте могут быть 3 согласные, и получаем ответ 801. Если сложнее то: import itertools, string [pre2] l = [] c = 3 while True: l1 = [''.join(i) for i in itertools.product('ксения', repeat=c) \ if i.count('е') < 3 and i.count('и') < 3 and i.count('я') < 3 \ and ((i[0] == 'к' and i.count('к') == 1 and i.count('с') == 0 and i.count('н') == 0) or \ (i[0] == 'с' and i.count('с') == 1 and i.count('к') == 0 and i.count('н') == 0) or \ (i[0] == 'н' and i.count('н') == 1 and i.count('с') == 0 and i.count('к') == 0))] l += l1 c += 1 if len(l1) == 0: break print(l) print(len(l)) [/pre2] Тут тоже ответ 801, а в ответе к заданию 1059.

Ответов - 1

polyakovss: [pre2] from itertools import product def f(x): return x.count('К') + x.count('С') + x.count('Н') count = 0 k = 3 while True: s = map(lambda x: ''.join(x), product('КСЕНИЯ',repeat = k)) n = 0 for x in s: if (x.count('Е') < 3 ) and (x.count('И') < 3 ) and (x.count('Я') < 3 ) and ((x[0] in 'КСН' and f(x) == 1) or f(x) == 0): n += 1 if n == 0: break count += n k += 1 print(count)[/pre2]Ответ: 1059. Ошибки в ответе к заданию нет.



полная версия страницы