题解:P13103 [GCJ 2019 Qualification] You Can Go Your Own Way

· · 题解

读题以后不难发现:只要直接把Lydia的路径中所有E换为S,S换为E即可。因为本题为正方形迷宫,向东与向南步数相等。
上代码:


t=int(input())
for i in range(1,t+1):
    n=int(input())
    p=input().strip()
    q=p.replace('E','K').replace('S','E').replace('K','S')    #借助中间量将E和S互换
    print(f'Case #{i}: {q}')    #格式化输出