其他分享
首页 > 其他分享> > 牛客华为机试HJ96

牛客华为机试HJ96

作者:互联网

原题传送门

1. 问题描述

2. Solution

import re
import sys

if sys.platform != "linux":
    sys.stdin = open("input/HJ96.txt")


def solve1(s):
    print(re.sub(r'(\d+)', r'*\1*', s))


# 0 1 2 3 4 5 6 7 8 9 10 11 12  13 14 15
# J k d i 2 3 4 k l o  w  e  9  0  a  3

def solve2(s):
    index_groups = []
    end = len(s) - 1
    while end > 0:
        while end >= 0 and not s[end].isdigit():
            end -= 1

        start = end
        while start >= 0 and not s[start].isalpha():
            start -= 1
        index_groups.append((start + 1, end))
        end = start

    for start, end in index_groups:
        print(s[start: end + 1])


for line in sys.stdin:
    s = line.strip()
    solve2(s)

标签:index,end,start,sys,牛客,while,groups,机试,HJ96
来源: https://www.cnblogs.com/junstat/p/16181397.html