正则表达式解法: import re inputs = re.findall(r'\b[AWSD]\d{1,2}\b', input()) results = [0,0] for i in inputs: if i[0] == 'A': results[0] -= int(i[1:]) elif i[0] == 'D': results[0] += int(i[1:]) elif i[0] == 'W': results[1] += int(i[1:]) else: results[1] -= int(i[1:]) print(f"{results[0]},{results[1]}", )
点赞

相关推荐

__Offer__:认识的室友啥也不回细节,线下面联想大模型一次通关我给我干不回了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务