解题思路:
注意事项:
参考代码:
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 人评分
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1372 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:1448 |
求圆的面积 (C语言代码)浏览:1271 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:717 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:661 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:468 |
川哥的吩咐 (C语言代码)浏览:611 |
矩形面积交 (C语言代码)浏览:1312 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:518 |
敲七 (C++代码)浏览:1056 |