陈正磊


私信TA

用户名:RossTran

访问量:13655

签 名:

晨兴理荒秽,带月荷锄归。

等  级
排  名 178
经  验 6681
参赛次数 15
文章发表 34
年  龄 0
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:


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可有可无,并且在我的电脑上测试样例可以通过。

但提交后无法通过。

20200917317123_sSTmQN.jpg

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

我也是,报格式错误
2020-11-03 19:46:01
  • «
  • 1
  • »