Форум » Обработка символьных строк » задача 24, №4752 » Ответить

задача 24, №4752

Пичугина: Не сходится ответ, больше чем нужно, хотя такая строка имеется [pre2]f=open('1.txt') for i in f: s=i mxs='' s1='' for i in range(len(s)): if s1.count('A')+s1.count('E')+s1.count('I')+s1.count('O')+s1.count('U')+s1.count('Y')<=7 and s[ i]!='.': s1+=s[ i] if s1.count('A')+s1.count('E')+s1.count('I')+s1.count('O')+s1.count('U')+s1.count('Y')>7 or s[ i]=='.': s1='' if len(s1)>len(mxs): mxs=s1 print(len(mxs), mxs) [/pre2]

Ответов - 3

Поляков: Спасибо, вы правы. Ответ исправлен - 90. Строка: CXXGKKRXLBEDFXJRXXILIGTBNGLVFRHZCSTXRVOLRZXCJNQGKVAGLKQLZYATGJFTMVVPJWDKPHFHMHCLRHVMXSKCKW.

ZaberovDV: Здравствуйте. Получаю в ответе 83. Что не так делаю? [pre2] s = open('24-181.txt').readline() m = '' s1 = '' for i in range(len(s)): if s1.count('A') + s1.count('E') + s1.count('I') + s1.count('O') + s1.count('U') + s1.count('Y') <= 7 and s[ i] != '.': s1 += s[ i] if s1.count('A') + s1.count('E') + s1.count('I') + s1.count('O') + s1.count('U') + s1.count('Y') > 7 or s[ i] == '.': s1 = '' if len(s1) > len(m): m = s1 print(len(m), m) [/pre2]

ZaberovDV: Все. Я нашел решение) [pre2] s = open('24-181.txt').readline().split('.') m = 0 x = set('AEIOUY') for i in s: s1 = i ind = [0] # для хранения индексов последних 7-ми гласных for j in range(len(i)): if s1[j] in x: if len(ind) > 7: ind.pop(0) ind.append(j) m = max(m, j - ind[0]) print(m) [/pre2] или [pre2] s = open('24-181.txt').readline().split('.') m = 0 for i in s: s1 = i.replace('A', '*').replace('E', '*'). \ replace('I', '*').replace('O', '*'). \ replace('U', '*').replace('Y', '*') ind = [0] # для хранения индексов последних 7-ми '*' for j in range(len(i)): if s1[j] == '*': if len(ind) > 7: ind.pop(0) ind.append(j) m = max(m, j - ind[0]) print(m) [/pre2] или [pre2] s = open('24-181.txt').readline() m = 0 x = set('AEIOUY') a = [0] # будем хранить индексы последних 7 символов 'AEIOUY' for i in range(len(s)): if s[ i] == '.': a = [ i] elif s[ i] in x: if len(a) > 7: a.pop(0) a.append(i) m = max(m, i - a[0]) print(m) [/pre2]




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