python 5678错误60分求解
查看原帖
python 5678错误60分求解
1299979
xfit楼主2024/11/2 21:09
import sys

def is_chs(s):
    if ord(s) >= 97 and ord(s) <= 122:
        return True
    return False

def is_number(s):
    if ord(s) >= 48 and ord(s) <= 57:
        return True
    return False

if __name__ == '__main__':
    chs = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9, 'k':10, 'l':11, 'm':12, 'n':13, 'o':14, 'p':15, 'q': 16, 'r':17, 's':18, 't':19, 'u':20, 'v':21, 'w':22, 'x':23, 'y':24, 'z':25}

    p1, p2, p3 = map(int, input().split())
    str_ogl = input()

    if str_ogl.find('-') == -1:
        print(str_ogl)
        sys.exit()

    pos = 0
    while pos != -1:
        if str_ogl[0] == '-':
            print('-', end='')
            str_ogl = str_ogl[1:]
            continue

        str_ins = ""
        pos = str_ogl.find('-', pos+1)

        ch_1 = str_ogl[pos-1]
        try:
            ch_2 = str_ogl[pos + 1]
        except:
            break

        if (ch_1 == ch_2 and str_ogl.count('-') != 1) or (ord(ch_1) > ord(ch_2)):
            continue
        elif ch_1 == '-' or ch_2 == '-':
            continue
        elif ch_1 == ch_2 and str_ogl.count('-') == 1:
            break
        elif (is_number(ch_1) and is_number(ch_2)) or (is_chs(ch_1) and is_chs(ch_2)):
            if p1 == 3:
                for i in range(ord(ch_1)+1, ord(ch_2)):
                    str_ins += '*' * p2
            else:
                if is_number(ch_1) and is_number(ch_2):
                    for i in range(int(ch_1)+1, int(ch_2)):
                        str_ins += str(i) * p2
                else:
                    j = 1
                    if p1 == 1:
                        for i in range(chs[f'{ch_1}']+1, chs[f'{ch_2}']):
                            str_ins += chr(ord(ch_1)+j) * p2
                            j += 1
                    elif p1 == 2:
                        for i in range(chs[f'{ch_1}']+1, chs[f'{ch_2}']):
                            str_ins += chr(ord(ch_1)+j).upper() * p2
                            j += 1
        else:
            if str_ogl.count('-') == 1:
                break
            else:
                continue

        if p3 == 2:
            str_ins = str_ins[::-1]

        ls_ogl = list(str_ogl)
        ls_ogl.insert(pos, str_ins)

        try:
            ls_ogl.remove('-')
        except:
            pass

        str_ogl = ''.join(ls_ogl)

    print(str_ogl)



2024/11/2 21:09
加载中...