特判使用教程
感谢涛巨
记录一下,省的以后忘记了。

/* Utility functions for writing output validators for the Kattis* problem format.** The primary functions and variables available are the following.* In many cases, the only functions needed are "init_io",* "wrong_answer", and "accept".** - init_io(argc, argv):*        initialization** - judge_in, judge_ans, author_out:*        std::istream objects for judge input file, judge answer*        file, and submission output file.** - accept():*        exit and give Accepted!** - accept_with_score(double score):*        exit with Accepted and give a score (for scoring problems)** - judge_message(std::string msg, ...):*        printf-style function for emitting a judge message (a*        message that gets displayed to a privileged user with access*        to secret data etc).** - wrong_answer(std::string msg, ...):*        printf-style function for exitting and giving Wrong Answer,*        and emitting a judge message (which would typically explain*        the cause of the Wrong Answer)** - judge_error(std::string msg, ...):*        printf-style function for exitting and giving Judge Error,*        and emitting a judge message (which would typically explain*        the cause of the Judge Error)** - author_message(std::string msg, ...):*        printf-style function for emitting an author message (a*        message that gets displayed to the author of the*        submission).  (Use with caution, and be careful not to let*        it leak information!)**/
#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 = "judgemessage.txt";
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) {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]);}// Set up feedbackdir first, as that allows us to produce feedback// files for errors in the other parameters.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());
}#include <regex>using namespace std;int main(int argc, char **argv) {init_io(argc, argv);int n, m, rounds = 0, no_matches = 0;judge_in >> n >> m;bool played[m][n][m][n];memset(played, 0, sizeof(played));regex match_regex("([A-Za-z])([0-9]+)-([A-Za-z])([0-9]+)");string line;while (getline(author_out, line)) {rounds++;istringstream iss(line);string match;bool pr[m][n];memset(pr, 0, sizeof(pr));while (iss >> match) {cout << match << endl;smatch mr;if (!regex_match(match, mr, match_regex)) {wrong_answer("Invalid match format in round %d: %s", rounds, match.c_str());}char c1 = mr[1].str()[0], c2 = mr[3].str()[0];int t1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 - 'A') : (c1 - 'a');int t2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 - 'A') : (c2 - 'a');int p1 = atoi(mr[2].str().c_str()) - 1, p2 = atoi(mr[4].str().c_str()) - 1;if (t1 < 0 || t2 < 0 || t1 >= m || t2 >= m || p1 < 0 || p2 < 0 || p1 >= n || p2 >= n) {wrong_answer("Invalid player reference in round %d: %s", rounds, match.c_str());}if (t1 == t2) {wrong_answer("Round %d: %s: Players from same team should not play against each other", rounds, match.c_str());}if (played[t1][p1][t2][p2]) {wrong_answer("Round %d: %s: Players have already played against each other", rounds, match.c_str());}if (pr[t1][p1] || pr[t2][p2]) {wrong_answer("Round %d: %s: Players have already played in this round", rounds, match.c_str());}pr[t1][p1] = true;pr[t2][p2] = true;played[t1][p1][t2][p2] = true;played[t2][p2][t1][p1] = true;no_matches++;}}if (rounds > n * (m-1) + 1) {wrong_answer("Too many rounds! Solution had %d rounds, but only %d allowed.", rounds, n * (m-1) + 1);}if (no_matches != m*n*(m-1)*n/2) {wrong_answer("There are %d matches missing in the schedule!", m*n*(m-1)*n/2 - no_matches);}accept();
}

修改的地方:





#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 =0;
const int EXITCODE_WA = 1;
const std::string FILENAME_AUTHOR_MESSAGE = "teammessage.txt";
const std::string FILENAME_JUDGE_MESSAGE = "judgemessage.txt";
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::ifstream author_out;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) {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.open(argv[3], std::ios_base::in);if (author_out.fail()) {judge_error("%s: failed to open %s\n", argv[0], argv[3]);///}
}#include <regex>using namespace std;int main(int argc, char **argv) {init_io(argc, argv);int n, m, rounds = 0, no_matches = 0;judge_in >> n >> m;bool played[m][n][m][n];memset(played, 0, sizeof(played));regex match_regex("([A-Za-z])([0-9]+)-([A-Za-z])([0-9]+)");string line;while (getline(author_out, line)) {rounds++;istringstream iss(line);string match;bool pr[m][n];memset(pr, 0, sizeof(pr));while (iss >> match) {cout << match << endl;smatch mr;if (!regex_match(match, mr, match_regex)) {wrong_answer("Invalid match format in round %d: %s", rounds, match.c_str());}char c1 = mr[1].str()[0], c2 = mr[3].str()[0];int t1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 - 'A') : (c1 - 'a');int t2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 - 'A') : (c2 - 'a');int p1 = atoi(mr[2].str().c_str()) - 1, p2 = atoi(mr[4].str().c_str()) - 1;if (t1 < 0 || t2 < 0 || t1 >= m || t2 >= m || p1 < 0 || p2 < 0 || p1 >= n || p2 >= n) {wrong_answer("Invalid player reference in round %d: %s", rounds, match.c_str());}if (t1 == t2) {wrong_answer("Round %d: %s: Players from same team should not play against each other", rounds, match.c_str());}if (played[t1][p1][t2][p2]) {wrong_answer("Round %d: %s: Players have already played against each other", rounds, match.c_str());}if (pr[t1][p1] || pr[t2][p2]) {wrong_answer("Round %d: %s: Players have already played in this round", rounds, match.c_str());}pr[t1][p1] = true;pr[t2][p2] = true;played[t1][p1][t2][p2] = true;played[t2][p2][t1][p1] = true;no_matches++;}}if (rounds > n * (m-1) + 1) {wrong_answer("Too many rounds! Solution had %d rounds, but only %d allowed.", rounds, n * (m-1) + 1);}if (no_matches != m*n*(m-1)*n/2) {wrong_answer("There are %d matches missing in the schedule!", m*n*(m-1)*n/2 - no_matches);}accept();
}

LDUOJ spj 修改相关推荐

  1. C/C++课程设计 之学生管理系统(一)

    文章目录 1) 案例一 2) 案例二 3) 案例三 4) 案例四 5) 案例五 6) 案例六 7) 案例七 8) 案例八 9) 案例九 10)案例十 11)案例十一 12)案例十二 13)案例十三 1 ...

  2. mysql并发更新数据,多用户并发修改数据解决方案。

    mysql并发更新数据,多用户并发修改数据解决方案. 在系统中,有一些如余额.资产.积分的数据,是要保证数据一致性的.如,一个人使用两个设备同时进行消费操作,如何保证数据一致性的问题. 我们一起来思考 ...

  3. 设置select下拉框不可修改的→“四”←种方法

    设置select下拉框为不可修改的几种方法: 因为select的特殊性,导致它不能像input表单一样简单地设置一个readonly来限制修改,所以,我们需要进行别的操作! 1.为下拉框添加样式,可以 ...

  4. 将页面元素置为不可修改Readonly,所有元素统一修改,统一调用

    使用JS方法,实现任何形式的元素的不可修改操作 <script language="javascript"> /**将所有元素置为不可修改 **/ function r ...

  5. Myeclipse中修改项目默认编码还是乱码?一步永久解决!

    在myeclipse中修改默认编码后发现项目还是乱码? 点击Windows选择Preferences 如下图

  6. linux修改mysql密码sa_如何修改SA口令,数据库SA密码怎么改?

    [问题现象]安装数据库的时候设置过SA口令,安装后不记得了?有没有办法可以修改数据库SA口令? [原因分析]各版本数据库更改SA口令的方法不一样,一般MSDE2000数据库安装时没有SA口令,SQL ...

  7. mysql修改校对集_MySQL 教程之校对集问题

    本篇文章主要给大家介绍mysql中的校对集问题,希望对需要的朋友有所帮助! 推荐参考教程:<mysql教程> 校对集问题 校对集,其实就是数据的比较方式. 校对集,共有三种,分别为:_bi ...

  8. ubuntu 修改时区、时间、同步网络时间、将时间写入硬件

    查看系统当前的时间状态 $ timedatectl statusLocal time: 六 2021-10-30 09:33:37 CSTUniversal time: 六 2021-10-30 01 ...

  9. 数据结构(03)— 数据处理基本操作(数据的查找、新增、删除、修改)

    我们先来看一个关于查找的例子.查找,就是从复杂的数据结构中,找到满足某个条件的元素.通常可从以下两个方面来对数据进行查找操作:​ 根据元素的位置或索引来查找: 根据元素的数值特征来查找. 针对上述两种 ...

  10. Ubuntu 16.04 安装后修改屏幕分辨率(xrandr: Failed to get size of gamma for output default)

    ubuntu 16.04 安装后分辨率只有一个选项 1024x768,使用 xrandr 命令出现错误: xrandr: Failed to get size of gamma for output ...

最新文章

  1. [转] 关于Jmail
  2. .Net Core迁移到MSBuild平台
  3. Intent, Bundle, ListView的简单使用
  4. css3 操作动画要点
  5. 计算机网络的带宽是指网络可通过的,计算机网络及带宽概念.ppt
  6. w10无法连到家庭组计算机,一键W10装机版无法进入家庭组如何处理
  7. [收藏]Mysql日期和时间函数
  8. linux之安装Apache服务
  9. 高通7227平台外接UBLOX的GPS模块数据接收不稳定问题
  10. Kaggle比赛——预测未来销售(一)
  11. 关于黑苹果耳机麦克风无法正常输入输出以及VoodooHDA启动慢 解决方法
  12. 头脑风暴 软件_头脑风暴和思维导图的最佳网站和软件
  13. flink watermark 生成机制与总结
  14. 有隐藏分区如何激活win7旗舰版
  15. 【Java笔记+踩坑】SpringBoot基础3——开发。热部署+配置高级+整合NoSQL/缓存/任务/邮件/监控
  16. PotPlayer打开视频没声音,显示DirectX有问题或者音频禁用怎么办?
  17. linux公共基础-初阶
  18. 沼跃鱼早已看穿了一切
  19. C++ Primer Plus (第六版)编程练习记录(chapter14 C++中的代码重用)
  20. 计算机设备养护知识试题,技术设备处设备管理知识培训试题库

热门文章

  1. 小米商城——HTML,CSS(附:源码)
  2. 【github】上有意思的深度学习项目——照片漫画风
  3. mvp的全称_MVP英文全称是什么
  4. Axure 8 网页滚动效果+APP上下垂直拖动效果
  5. STM8S003超声波测距
  6. 洛谷P1007独木桥题解--zhengjun
  7. 快手短视频怎么同步到头条?
  8. Access时间日期比较查询的方法总结
  9. win10桌面图标全部变成白色的怎么办
  10. 团队项目(3) -- 搭载于MSP430F6638_FFTB的仿《像素小鸟》小游戏