解题思路:
这道题就是常规思路吧,处理好数据然后按照要求去进行模拟应该就没什么问题。
注意:题目在行走的途中到达终点即算作到达了终点,而不是行走完成之后再进行判断是否到达终点。
注意事项:
参考代码:
def f(n): for t in range(n): m = int(input()) G = [] for i in range(m): #记录图 G = G + [it for it in input().strip().split()] x,y = 0,0 for i in range(m): #找出S的坐标 flag = 0 for j in range(m): if G[i][j] == 'S': x = i y = j flag = 1 break if flag: break k = int(input().strip()) for i in range(k): temp = input().strip() x_now = x y_now = y for j in range(len(temp)): if temp[j] == 'L': y_now = y_now - 1 if y_now < 0: print('I am out!') break if G[x_now][y_now] == 'T': print('I get there!') break if G[x_now][y_now] == '#': print('I am dizzy!') break elif temp[j] == 'R': y_now = y_now + 1 if y_now > m-1: print('I am out!') break if G[x_now][y_now] == 'T': print('I get there!') break if G[x_now][y_now] == '#': print('I am dizzy!') break elif temp[j] == 'U': x_now = x_now - 1 if x_now < 0: print('I am out!') break if G[x_now][y_now] == 'T': print('I get there!') break if G[x_now][y_now] == '#': print('I am dizzy!') break elif temp[j] == 'D': x_now = x_now + 1 if x_now > m-1: print('I am out!') break if G[x_now][y_now] == 'T': print('I get there!') break if G[x_now][y_now] == '#': print('I am dizzy!') break else: print('I have no idea!') if __name__ == '__main__': n = int(input()) f(n)
0.0分
0 人评分
人见人爱A+B (C语言代码)浏览:777 |
剔除相关数 (C语言代码)浏览:1841 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:555 |
C二级辅导-同因查找 (C语言代码)浏览:564 |
C语言程序设计教程(第三版)课后习题12.6 (C语言代码)浏览:794 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:561 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:668 |
三角形 (C语言代码)浏览:917 |
简单的a+b (C语言代码)浏览:512 |
杨辉三角 (C语言代码)浏览:679 |