Attachment '2012-11-09.powtor.py'
Download 1 #!/usr/bin/env python
2 # coding: utf
3 '''
4 Дана непустая строка s. Нужно найти такое наибольшее число k и строку t, что s совпадает со строкой t, выписанной k раз подряд. Вывести k. Примеры: aaaaa → 5; abcabc → 2, ababa → 1
5 '''
6
7 # Весьма прямолнейный вариант
8 string = raw_input("Введите строку: ")
9 L = len(string)
10 # Нет смысла проверять подстроки длиннее половины строки
11 for i in xrange(1,L/2):
12 # Подстроки некратной длины тоже не надо проверять
13 if L%i: continue
14 if string[:i]*(L/i) == string:
15 print L/i
16 break
17 else:
18 print 1
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2012-11-15 19:57:33, 0.5 KB) [[attachment:2012-11-09.cifry.py]]
- [get | view] (2012-11-22 19:36:51, 1.2 KB) [[attachment:2012-11-09.f2n.rec.py]]
- [get | view] (2012-11-15 19:57:57, 0.8 KB) [[attachment:2012-11-09.powtor.py]]
- [get | view] (2012-11-15 19:57:14, 1.2 KB) [[attachment:2012-11-09.slowo.py]]
You are not allowed to attach a file to this page.