Advertisement
stupid_pro

24

Jun 16th, 2023
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.81 KB | None | 0 0
  1. with open('1-1.txt') as file:
  2.     s = file.readline()
  3. c = 1
  4. ans = 0
  5. for i in range(len(s) - 1):
  6.     if s[i] != s[i + 1]:
  7.         c += 1
  8.         ans = max(ans, c)
  9.     else:
  10.         c = 1
  11. print(ans)
  12.  
  13. with open('1-2.txt') as file:
  14.     s = file.readline()
  15. c = 1
  16. ans = 0
  17. for i in range(len(s) - 1):
  18.     if (s[i] + s[i + 1]) != 'IT' and (s[i] + s[i + 1]) != 'TI':
  19.         c += 1
  20.         ans = max(ans, c)
  21.     else:
  22.         c = 1
  23. print(ans)
  24. s = s.replace('IT', 'I T').replace('TI', 'T I')
  25. print(max(len(c) for c in s.split()))
  26.  
  27. with open('1-3.txt') as file:
  28.     s = file.readline()
  29. c = 0
  30. for i in range(len(s) - 2):
  31.     if (s[i] in 'A E F') and (s[i + 1] in 'A B C') and (s[i + 2] in 'B C D F') and \
  32.             (s[i] != s[i + 1]) and (s[i + 1] != s[i + 2]) and (s[i] != s[i + 2]):
  33.         c += 1
  34. print(c)
  35.  
  36. with open('1-4.txt') as file:
  37.     s = file.readline()
  38. sub = 'CAT'
  39. while sub in s:
  40.     sub += 'CAT'
  41. sub = 'CAT' * 2 + ''
  42. print(sub in s)
  43.  
  44. with open('1-3.txt') as file:
  45.     s = file.readline()
  46. s = s.replace('E', ' ').replace('F', ' ')
  47. print(max(len(c) for c in s.split()))
  48.  
  49. with open('1-3.txt') as file:
  50.     s = file.readline()
  51. c = 0
  52. for i in range(len(s) - 3):
  53.     if (s[i] in 'A C E') and (s[i + 1] != s[i]) and (s[i + 1] != s[i + 2]) and (s[i + 2] in 'A D F') and (s[i + 3] == s[i]):
  54.         c += 1
  55. print(c)
  56.  
  57. with open('1-1.txt') as file:
  58.     s = file.readline()
  59. c = 1
  60. ans = 0
  61. for i in range(len(s) - 1):
  62.     h = s[i] + s[i + 1]
  63.     if h not in 'XX YY':
  64.         c += 1
  65.         ans = max(ans, c)
  66.     else:
  67.         c = 1
  68. print(ans)
  69. while 'XX' in s:
  70.     s = s.replace('XX', 'X X')
  71. while 'YY' in s:
  72.     s = s.replace('YY', 'Y Y')
  73. print(max(len(c) for c in s.split()))
  74.  
  75. with open('1-2.txt') as file:
  76.     s = file.readline()
  77. c = 0
  78. for i in range(len(s) - 4):
  79.     h = s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4]
  80.     copyh = h
  81.     h = h[::-1]
  82.     if h == copyh:
  83.         c +=1
  84. print(c)
  85.  
  86. with open('2-2 (1).txt') as file:
  87.     s = file.readline()
  88. c = 0
  89. for i in range(len(s) - 2):
  90.     if s[i] <= s[i + 1] <= s[i + 2]:
  91.         c += 1
  92. print(c)
  93.  
  94. with open('2-2 (1).txt') as file:
  95.     s = file.readline()
  96. ans = []
  97. add = s[0]
  98. for i in range(len(s) - 1):
  99.     if s[i] <= s[i + 1]:
  100.         add += s[i + 1]
  101.     else:
  102.         ans.append(add)
  103.         add = s[i + 1]
  104. print(ans)
  105. t = max(len(c) for c in ans)
  106. print(t)
  107. for i in range(len(ans)):
  108.     if len(ans[i]) == t:
  109.         print(ans[i], len(ans[i]), t)
  110.         break
  111.  
  112. with open('2-3.txt') as file:
  113.     s = file.readline()
  114. for c in 'QWERTYUIOPASDFGHJKLZXCVBNM':
  115.     s = s.replace(c, ' ')
  116. s = [int(c) for c in s.split()]
  117. ans = 0
  118. for i in range(len(s)):
  119.     if int(s[i]) % 2 == 1:
  120.        ans = max(ans, s[i])
  121. print(ans)
  122.  
  123. with open('2-4.txt') as file:
  124.     s = file.readline()
  125. s = s.replace('MOON', 'MOO OON')
  126. print(max(len(c) for c in s.split()))
  127.  
  128. c = 0
  129. with open('2-5.txt') as file:
  130.     for line in file:
  131.         s = line
  132.         for i in range(len(s) - 3):
  133.             if s[i] == 'M' and s[i + 2] == 'H' and s[i + 3] == 'P':
  134.                 c += 1
  135.                 break
  136. print(c)
  137.  
  138. min_c = 10 ** 10
  139. min_str = ''
  140. cntr = 0
  141. with open('2-5.txt') as file:
  142.     for line in file:
  143.         s = line
  144.         cntr += s.count('R')
  145.         if s.count('F') < min_c:
  146.             min_c = s.count('F')
  147.             min_str = s
  148. work = min_str.strip()
  149. d = {x: work.count(x) for x in sorted(set(work))}
  150. print(max(d.values()))
  151. print(d)
  152. print('R', cntr)
  153.  
  154. ans = []
  155. with open('2-2 (1).txt') as file:
  156.     s = file.readline()
  157.     for i in range(len(s) - 8):
  158.         if s[i] <= s[i + 1] <= s[i + 2] <= s[i + 3] <= s[i + 4] <= s[i + 5] <= s[i + 6] <= s[i + 7] <= s[i + 8]:
  159.             ans.append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] + s[i + 5] + s[i + 6] + s[i + 7] + s[i + 8])
  160. print(ans[0], len(ans))
  161.  
  162. with open('2-3.txt') as file:
  163.     s = file.readline()
  164. for c in 'QWERTYUIOPASDFGHJKLZXCVBNM':
  165.     s = s.replace(c, ' ')
  166. a = [int(c) for c in s.split() if len(c) == 5 and int(c) % 3 == 0]
  167. print(len(a))
  168. print(a) #неправильно, учитываеются 4-е числа
  169.  
  170. with open('2-6.txt') as file:
  171.     s = file.readline()
  172. s = s.replace('PEP8', 'PEP EP8')
  173. print(max(len(c) for c in s.split()))
  174.  
  175. max_len = -10 ** 10
  176. cur_len = ''
  177. cntr = 0
  178. with open('2-5.txt') as file:
  179.     for line in file:
  180.         s = line
  181.         c = 1
  182.         l = s[0]
  183.         cntr += s.count('U')
  184.         for i in range(len(s) - 1):
  185.             if s[i] == s[i + 1]:
  186.                 c += 1
  187.                 l += s[i + 1]
  188.             else:
  189.                 if c > max_len:
  190.                     max_len = c
  191.                     cur_len = line
  192.                 l = s[i + 1]
  193.                 c = 1
  194. print(cur_len)
  195. cur_len = cur_len.strip()
  196. d = {x: cur_len.count(x) for x in sorted(set(cur_len))}
  197. print(min(d.values()))
  198. print(d)
  199. print('U', cntr)
  200.  
  201.  
  202.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement