"""练习 7:模拟 U/D/L/R 方向移动,输出终点坐标和移动步数。 坐标约定:向右 x+1,向左 x-1,向上 y+1,向下 y-1。 输入一行由 U、D、L、R 组成的方向序列。 学习说明: - strip() 去掉首尾空白,upper() 让小写指令也可以使用。 - x、y 从原点 (0, 0) 开始;moves 字典把方向映射到坐标变化量 (dx, dy)。 - for 循环逐个读取指令;不认识的字符跳过,合法指令则更新坐标和步数。 - 最终坐标表示位置;steps 统计实际执行的有效移动数。 """ directions = input().strip().upper() x = y = steps = 0 moves = {"U": (0, 1), "D": (0, -1), "L": (-1, 0), "R": (1, 0)} for direction in directions: if direction not in moves: continue dx, dy = moves[direction] x += dx y += dy steps += 1 print("position:", x, y) print("steps:", steps)