| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #pragma once |
|
|
| #include <sys/stat.h> |
| #include <cassert> |
| #include <cstdarg> |
| #include <cstdlib> |
| #include <iostream> |
| #include <fstream> |
| #include <sstream> |
|
|
| typedef void (*feedback_function)(const std::string &, ...); |
|
|
| const int EXITCODE_AC = 42; |
| const int EXITCODE_WA = 43; |
| const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt"; |
| const std::string FILENAME_JUDGE_MESSAGE = "null"; |
| const std::string FILENAME_JUDGE_ERROR = "judgeerror.txt"; |
| const std::string FILENAME_SCORE = "score.txt"; |
|
|
| #define USAGE "%s: judge_in judge_ans feedback_dir < author_out\n" |
|
|
| std::ifstream judge_in, judge_ans; |
| std::istream author_out(std::cin.rdbuf()); |
|
|
| char *feedbackdir = NULL; |
|
|
| void vreport_feedback(const std::string &category, |
| const std::string &msg, |
| va_list pvar) { |
| std::ostringstream fname; |
| if (feedbackdir) |
| fname << feedbackdir << '/'; |
| fname << category; |
| FILE *f = fopen(fname.str().c_str(), "a"); |
| assert(f); |
| vfprintf(f, msg.c_str(), pvar); |
| fclose(f); |
| } |
|
|
| void report_feedback(const std::string &category, const std::string &msg, ...) { |
| va_list pvar; |
| va_start(pvar, msg); |
| vreport_feedback(category, msg, pvar); |
| } |
|
|
| void author_message(const std::string &msg, ...) { |
| va_list pvar; |
| va_start(pvar, msg); |
| vreport_feedback(FILENAME_AUTHOR_MESSAGE, msg, pvar); |
| } |
|
|
| void judge_message(const std::string &msg, ...) { |
| va_list pvar; |
| va_start(pvar, msg); |
| vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); |
| } |
|
|
| void wrong_answer(const std::string &msg, ...) { |
| va_list pvar; |
| va_start(pvar, msg); |
| vreport_feedback(FILENAME_JUDGE_MESSAGE, msg, pvar); |
| exit(EXITCODE_WA); |
| } |
|
|
| void judge_error(const std::string &msg, ...) { |
| va_list pvar; |
| va_start(pvar, msg); |
| vreport_feedback(FILENAME_JUDGE_ERROR, msg, pvar); |
| assert(0); |
| } |
|
|
| void accept() { |
| exit(EXITCODE_AC); |
| } |
|
|
| void accept_with_score(double scorevalue) { |
| report_feedback(FILENAME_SCORE, "%.9le", scorevalue); |
| exit(EXITCODE_AC); |
| } |
|
|
|
|
| bool is_directory(const char *path) { |
| if(std::string(path) == std::string("/dev")) return 1; |
| struct stat entry; |
| return stat(path, &entry) == 0 && S_ISDIR(entry.st_mode); |
| } |
|
|
| void init_io(int argc, char **argv) { |
| if(argc < 4) { |
| fprintf(stderr, USAGE, argv[0]); |
| judge_error("Usage: %s judgein judgeans feedbackdir [opts] < userout", argv[0]); |
| } |
|
|
| |
| |
| if (!is_directory(argv[3])) { |
| judge_error("%s: %s is not a directory\n", argv[0], argv[3]); |
| } |
| feedbackdir = argv[3]; |
|
|
| judge_in.open(argv[1], std::ios_base::in); |
| if (judge_in.fail()) { |
| judge_error("%s: failed to open %s\n", argv[0], argv[1]); |
| } |
|
|
| judge_ans.open(argv[2], std::ios_base::in); |
| if (judge_ans.fail()) { |
| judge_error("%s: failed to open %s\n", argv[0], argv[2]); |
| } |
|
|
| author_out.rdbuf(std::cin.rdbuf()); |
| } |