Pat乙级1029题——旧键盘(Python)

代码如下

def oldKeyboard():
    standStr = raw_input()
    inputStr = raw_input()
    result = []
    i, j = 0, 0
    while i < len(standStr):
        if standStr[i] == inputStr[j]:
            if j < (len(inputStr)-1):
                j += 1
        else:
            diff = standStr[i]
            if diff.islower():
                diff = diff.upper()
            if diff not in result:
                result.append(diff)
        i += 1

    print ('').join(result)

if __name__ == '__main__':
    oldKeyboard()

测试结果

Pat乙级1029题——旧键盘(Python)_第1张图片

你可能感兴趣的:(python,PAT)