import java.io.*;
import java.util.*;
/**
* Test for <strong>modified</strong> old judge.
* <p/>
* <strong>BEFORE TESTING</strong>
* <ul>
* <li>
* Set temp path in <strong>judge.properties</strong> file.
* </li>
* <li>
* Copy data files into <strong>temp/data</strong> path, classify the data files by problem name.
* </li>
* <li>
* Copy code files into <strong>temp/codes</strong> path, classify the codes by user name.
* </li>
* <li>
* Copy <strong>judge core file</strong> into <strong>temp/bin</strong> path.
* </li>
* </ul>
* <p/>
* <strong>DATA SETTING</strong>
* Data score = 100 / number of cases
* If 100 <strong>Mod</strong> cases is not 0, divide the score down to nearest integer.
*
* @author <a href="mailto:lyhypacm@gmail.com">fish</a>
*/
public class Main {
// store problem's test case list.
private static Map<String, List<String>> problemMap = new HashMap<>();
// store user's codes by user name, and we identify the codes by name.
private static Map<String, Map<String, String>> codeMap = new HashMap<>();
private static String judgeCoreLocation;
@SuppressWarnings("UnusedDeclaration")
private static String temporaryPath;
private static String dataPath;
private static final Result[] JUDGE_RESULT = new Result[]{
Result.CompilationError, Result.Accepted, Result.PresentationError, Result.TimeLimitExceeded,
Result.MemoryLimitExceeded, Result.WrongAnswer, Result.OutputLimitExceeded, Result.CompilationError,
Result.RuntimeError, Result.RuntimeError, Result.RuntimeError, Result.RuntimeError, Result.SystemError,
Result.RuntimeError, Result.SystemError, Result.RuntimeError
};
public static void main(String[] args) {
try {
init();
// System.out.println("=======List start=======");
// listAllProblems();
// listAllCodes();
// System.out.println("========List end========");
} catch (Exception e) {
e.printStackTrace();
return;
}
judge();
}
/**
* List all codes' information, including the users' name
* and their codes' name and their codes' path.
*/
@SuppressWarnings("UnusedDeclaration")
private static void listAllCodes() {
for (String key : codeMap.keySet()) {
Map<String, String> map = codeMap.get(key);
System.out.println(key + ": " + map.size());
for (String name : map.keySet()) {
System.out.println(" " + name + ": " + map.get(name));
}
System.out.println();
}
}
/**
* List all problems' information, including problems' name and their test cases' path.
*/
@SuppressWarnings("UnusedDeclaration")
private static void listAllProblems() {
for (String key : problemMap.keySet()) {
List<String> list = problemMap.get(key);
System.out.println(key + ": " + list.size());
for (String value : list) {
System.out.println(" " + value);
}
System.out.println();
}
}
/**
* Judge all the codes in the <strong>data</strong> folder.
*/
private static void judge() {
System.out.println("==========judge begin==========");
for (String user : codeMap.keySet()) {
System.out.println("current user: " + user);
int userScore = 0;
for (String problem : problemMap.keySet()) {
List<String> testCases = problemMap.get(problem);
int totalScore = 0, scorePerCase = testCases.size() == 0 ? 0 : 100 / testCases.size();
System.out.println(" problem: " + problem);
System.out.print(" ");
boolean first = true;
boolean nullCode = false;
boolean compileError = false;
for (String testCase : testCases) {
Result result;
if (nullCode)
result = Result.NullCode;
else if (compileError)
result = Result.CompilationError;
else
result = judgeTestCase(codeMap.get(user), problem, testCase, first);
first = false;
if (result == Result.NullCode)
nullCode = true;
if (result == Result.CompilationError)
compileError = true;
switch (result) {
case Accepted:
System.out.print('A');
totalScore += scorePerCase;
break;
case WrongAnswer:
System.out.print('W');
break;
case TimeLimitExceeded:
System.out.print('T');
break;
case RuntimeError:
System.out.print('R');
break;
case CompilationError:
System.out.print('C');
break;
case SystemError:
System.out.print("S");
break;
case PresentationError:
System.out.print("P");
break;
case MemoryLimitExceeded:
System.out.print("M");
break;
case OutputLimitExceeded:
System.out.print("O");
break;
case NullCode:
default:
System.out.print('.');
break;
}
// System.out.println(result);
}
userScore += totalScore;
System.out.println(" " + totalScore);
}
System.out.println(" score: " + userScore);
}
System.out.println("===========judge end===========");
}
/**
* Judge a simple test case according to the coder's code information and problem's information.
*
* @param codes code list
* @param problem problem name
* @param testCase test case's <strong>absolute</strong> path
* @return result of judge core returns
*/
@SuppressWarnings({"UnusedAssignment", "UnusedDeclaration"})
private static Result judgeTestCase(Map<String, String> codes, String problem,
String testCase, boolean isFirstCase) {
String sourceFile;
if (codes.get(problem) == null)
return Result.NullCode;
else
sourceFile = codes.get(problem);
Runtime runtime = Runtime.getRuntime();
int userId = 1;
int problemId = 1;
int timeLimit = 2000;
int memoryLimit = 65535;
int outputLimit = 8192;
boolean isSpj = false;
int languageId = 2; // C++
String inputFile = testCase + ".in";
String outputFile = testCase + ".out";
try {
Process process = runtime.exec(buildCommand(userId, sourceFile, problemId, dataPath, temporaryPath,
timeLimit, memoryLimit, outputLimit, isSpj, languageId, inputFile, outputFile, isFirstCase));
InputStream inputStream = process.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
StringBuilder stringBuilder = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
来自 UESTC ACM 的在线裁判核心分叉
83 浏览量
2023-10-08
13:19:19
上传
评论
收藏 38KB ZIP 举报
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6650
最新资源
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
- 20-天天果园项目.rar
- 26-朴素贝叶斯分类.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈