解题思路:
注意事项:
参考代码:
package 模拟; import java.util.Scanner; public class T1522我们的征途是星辰大海 { static int n; static char[][] arr; public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt();//T次询问 while (T-->0) { n=sc.nextInt(); arr=new char[n][n]; int x = 0,y = 0;//起始坐标 for (int i = 0; i < n; i++) { arr[i]=sc.next().toCharArray();//接收数组的内容 例如接受地图S.#T } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(arr[i][j]=='S') {//找到起始位置保持x,y坐标 x=i; y=j; } } } int Q = sc.nextInt();//Q次询问 for (int i = 0; i < Q; i++) { String str=sc.next(); f(x,y,str);//每次询问就进行一次模拟 //传入x,y坐标 str 是几行指令RD DR } } } private static void f(int x, int y, String str) { // TODO Auto-generated method stub char[] a=str.toCharArray();//指令赋值给a for (int i = 0; i < a.length; i++) {//循环a次指令 if(a[i]=='R') { y++; }else if(a[i]=='L') { y--; }else if(a[i]=='U') { x--; }else { x++; }//把输入的LRUD判断进行走路 if(x<0||y<0||x>=n||y>=n){//越界情况 System.out.println("I am out!"); return; } if(arr[x][y]=='#') {//遇到障碍 System.out.println("I am dizzy!"); return; } if(arr[x][y]=='T') {//到达终点 System.out.println("I get there!"); return; } } //走完所有之后没有到达终点 System.out.println("I have no idea!"); return; } }
0.0分
1 人评分
WU-复数求和 (C++代码)浏览:1995 |
简单的a+b (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:533 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:664 |
1011题解浏览:760 |
神奇的fans (C语言代码)浏览:976 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:376 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:521 |
拆分位数 (C语言代码)浏览:441 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:728 |