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()

测试结果

这里写图片描述

没有更多推荐了,返回首页