首页 > java提交答案却一直提示"返回非零"
头像
牛客669064602号
编辑于 2021-05-29 22:39
+ 关注

java提交答案却一直提示"返回非零"

华为机试题
题目名称:简单错误记录
问下为啥自测用例可以过,但是提交答案却一直提示返回非零


提交代码如下:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<String> fileList = new ArrayList<String>();
		List<String> lineList = new ArrayList<String>();
		List<Integer> countList = new ArrayList<Integer>();
		while (in.hasNextLine()) {
			String str = in.nextLine();
			String line = str.split(" ")[1];
			int pos1 = str.lastIndexOf("\\");
			int pos2 = str.lastIndexOf(" ");
			String fileName = str.substring(pos1 + 1, pos2);
			if (fileName.length() > 16) {
				fileName = fileName.substring(fileName.length() - 16);
			}
			if (!fileList.contains(fileName)) {
				fileList.add(fileName);
				lineList.add(line);
				countList.add(1);
			} else {
				int loc = fileList.indexOf(fileName);
				if (lineList.get(loc).equals(line)) { // 相同错误
					countList.set(loc, countList.get(loc) + 1);
				} else {
					fileList.add(fileName);
					lineList.add(line);
					countList.add(1);
				}
			}
		}
		for (int j = fileList.size() - 8; j <= fileList.size() - 1; j++) {
			System.out.println(fileList.get(j) + " " + lineList.get(j) + " " + countList.get(j));
		}
	}

}

全部评论

(1) 回帖
加载中...
话题 回帖