import java.util.ArrayList; import java.util.Scanner; public class Main{ public static ArrayList<String> list=new ArrayList<String>(); public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0) { sc.nextLine(); int n=sc.nextInt(); char arr[][]=new char[n][n]; int x=0,y=0; for (int i = 0; i < n; i++) {//输入 String str=sc.next(); for (int j = 0; j <str.length(); j++) { arr[i][j]=str.charAt(j); if (arr[i][j]=='S') { x=i; y=j; } } } int m=sc.nextInt();//指令条数 for (int i = 0; i < m; i++) { //直接判断指令,且输出答案 String ZhiLin=sc.next(); name(arr, ZhiLin, x, y); } } //输出结果 for (String item : list) { System.out.println(item); } } //判断指令,返回结果 public static void name(char arr[][],String Zhi,int x,int y) { for (int i = 0; i <Zhi.length(); i++) { char c=Zhi.charAt(i); if (c=='R') { y++; }if (c=='U') { x--; }if (c=='L') { y--; }if (c=='D') { x++; } //判断位置 if (x<0 || y<0 || x>=arr.length || y>=arr[0].length) { list.add("I am out!"); return ;//退出 }else if(arr[x][y]=='#'){ list.add("I am dizzy!"); return ; }else if (arr[x][y]=='T') { list.add("I get there!"); return ; } } //未能到达终点 list.add("I have no idea!"); //return ; 不能加return,加了不能通过。 } }
-------------------------
这个return可有可无,并且在我的电脑上测试样例可以通过。
但提交后无法通过。
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:534 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:681 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1115 |
输出九九乘法表 (C语言代码)浏览:555 |
简单的a+b (C语言代码)浏览:335 |
【计算球体积】 (C语言代码)浏览:1101 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:664 |
C二级辅导-计负均正 (C语言代码)浏览:480 |
图形输出 (C语言代码)浏览:937 |
拆分位数 (C语言代码)浏览:441 |