-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
67 lines (56 loc) · 2.44 KB
/
Test.java
File metadata and controls
67 lines (56 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.*;
import java.nio.file.*;
import java.util.*;
public class Test {
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String CYAN = "\u001B[36m";
public static void main(String[] args) {
String outFile = "../out.txt";
String ansFile = "../ans.txt";
if (!Files.exists(Paths.get(outFile))) {
System.out.println(RED + "Output file not found!" + RESET);
System.exit(1);
}
if (!Files.exists(Paths.get(ansFile))) {
System.out.println(RED + "Answer file not found!" + RESET);
System.exit(1);
}
try {
List<String> outLinesRaw = Files.readAllLines(Paths.get(outFile));
List<String> ansLinesRaw = Files.readAllLines(Paths.get(ansFile));
// 预处理:去除空行和首尾空格
List<String> outLines = preprocessLines(outLinesRaw);
List<String> ansLines = preprocessLines(ansLinesRaw);
int maxLen = Math.max(outLines.size(), ansLines.size());
for (int i = 0; i < maxLen; i++) {
String outLine = i < outLines.size() ? outLines.get(i) : "<no line>";
String ansLine = i < ansLines.size() ? ansLines.get(i) : "<no line>";
if (!outLine.equals(ansLine)) {
System.out.println(RED + "Wrong Answer" + RESET);
System.out.println("---------------------");
System.out.println(CYAN + "Difference at line " + (i + 1) + RESET);
System.out.println(YELLOW + "Expected: " + RESET + ansLine);
System.out.println(YELLOW + "Received: " + RESET + outLine);
System.exit(1);
}
}
System.out.println(GREEN + "Accepted" + RESET);
} catch (IOException e) {
System.out.println(RED + "Error reading files: " + e.getMessage() + RESET);
System.exit(1);
}
}
private static List<String> preprocessLines(List<String> lines) {
List<String> result = new ArrayList<>();
for (String line : lines) {
String trimmed = line.trim();
if (!trimmed.isEmpty()) {
result.add(trimmed);
}
}
return result;
}
}