
Python
- 4 ответа
- 0 вопросов
4
Вклад в тег
handlers = {
'ADD': lambda x: print('ADD with %s' % x),
'DELETE': lambda x: print('DELETE with %s' % x),
'INSERT': lambda x: print('INSERT with %s' % x)
}
for _ in range(int(input())):
handler_name, arg = input().split()
handler = handlers.get(
handler_name, lambda _: print("%s wasn't found" % handler_name)
)
handler(arg)
% cat input.txt
4
DELETE 10
INSERT 2
ADD 15
SELECT 7
% python3 ans.py < input.txt
DELETE with 10
INSERT with 2
ADD with 15
SELECT wasn't found
import collections
genome = 'aaaabbcaa'
result = collections.deque()
genome += '$'
last = genome[0]
counter = 1
for c in genome[1:]:
if c == last:
counter += 1
else:
result.append('%s%d' % (last, counter))
last = c
counter = 1
print(''.join(result))