Python:每日一题 95
- 2017-11-27 14:50:00
- 六月
- 来源:
- http://bbs.fishc.com/thread-96065-1-1.html
- 转贴 621
- FishC
- FishC
- FishC
- FishC
- Little turtle
- Little turtle
- Python
- FishC
结果为
- (3)FishC
- (2)FishC
- (1)FishC
- (0)FishC
- (1)Little turtle
- (0)Little turtle
- (0)Python
- (0)FishC
我的解法:
- str1 = '''FishC
- FishC
- FishC
- FishC
- Little turtle
- Little turtle
- Python
- FishC'''
- list1 = str1.split('n')
- count = 0
- next = list1[-1]
- list1[-1] = '(0)' + list1[-1]
- for i in range(-2, -len(list1) - 1, -1):
- if list1[i] == next:
- count += 1
- else:
- count = 0
- next = list1[i]
- list1[i] = '(%d)'%count + list1[i]
- print('n'.join(list1))
发表评论