Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Last active August 29, 2015 14:22
Show Gist options
  • Save amoshyc/f9863c805b0bf5c82ac5 to your computer and use it in GitHub Desktop.
Save amoshyc/f9863c805b0bf5c82ac5 to your computer and use it in GitHub Desktop.
IPSC 2014 Problem A – Adjusting passwords

IPSC 2014 Problem A – Adjusting passwords

題目

注意第二筆 Sample Input!需考慮直接重打的情況。

def adjust(ans, query):
    Na = len(ans)
    Nq = len(query)

    
    idx = 0
    while idx < min(Na, Nq) and ans[idx] == query[idx]:
        idx += 1

    backspace = Nq - idx
    rekeyin = Na - idx

    return backspace + rekeyin + 1, '<'*backspace + ans[idx:] + '*'
    
    
T = int(input())
for _ in range(T):
    blank_line = input()
    ans = input()
    query = input()

    
    cnt_retype = 1 + len(ans) + 1
    cnt_adjust, result = adjust(ans, query)

    if cnt_retype < cnt_adjust:
        print('*' + ans + '*')
    else:
        print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment