解题思路:
注意事项:
参考代码:
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 人评分
简单的a+b (C语言代码)浏览:573 |
C语言训练-求PI* (C语言代码)浏览:613 |
C语言训练-亲密数 (C语言代码)浏览:682 |
小九九 (C语言描述,不看要求真坑爹)浏览:984 |
数组输出 (C语言代码)浏览:700 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:582 |
矩阵的对角线之和 (C语言代码)浏览:1343 |
矩阵转置 (C语言代码)浏览:782 |
1162答案错误,为什么浏览:640 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:713 |