版本比较
【教程】C++ 造数据一条龙教程Ⅱ
正文
增加 57 行删除 76 行
18 行未改动19202122232324252627282930313233282930313233343536374 行未改动424344454647484946474849505152534 行未改动585960616263646562636465666768697071727373747576773 行未改动8182838485868586878889907 行未改动98991001011021031041021031041051061071088 行未改动11711811912012112212312412512612712812913013113213313412112212312412512612712812913013113213313413513613713827 行未改动16616716816917017017117217317417517617717817918018118218318418518618717517617717817918018118218318418518618718818919019110 行未改动20220320420520620720620720820921021164 行未改动2762772782792802812802812822832842852862872882892892902912912922932942954 行未改动3003013023033043053063073083093103113123133143153163173183193203213223233043053063073 行未改动31131231331433531531631731831932023 行未改动18 行未改动#include <bits/stdc++.h>using namespace std;mt19937 gen;long long rand_ll(long long l, long long r) { return uniform_int_distribution<long long>(l, r)(gen); return uniform_int_distribution<long long>(l, r)(gen);}
// 编译后命令行输入 gen.exe <种子> <a,b 下界> <a,b 上界> 以运行int main(int argc, char* argv[]) { unsigned t = atoi(argv[1]); gen.seed(t * 114514 + 7891); // 根据第一个参数设定生成器种子 int l = atoi(argv[2]), r = atoi(argv[3]); cout << rand_ll(l, r) << " " << rand_ll(l, r) << "\n"; return 0; unsigned t = atoi(argv[1]); gen.seed(t * 114514 + 7891); // 根据第一个参数设定生成器种子 int l = atoi(argv[2]), r = atoi(argv[3]); cout << rand_ll(l, r) << " " << rand_ll(l, r) << "\n"; return 0;}```
:::4 行未改动#include <bits/stdc++.h>using namespace std;
int main() { int a, b; cin >> a >> b; cout << a + b; return 0; int a, b; cin >> a >> b; cout << a + b; return 0;}```
:::4 行未改动#include <bits/stdc++.h>using namespace std;
int main() { unsigned a, b; // 故意写成 unsigned 让对拍时出错 cin >> a >> b; cout << a + b; return 0; unsigned a, b; // 故意写成 unsigned 让对拍时出错 cin >> a >> b; cout << a + b; return 0;}```
:::
:::success[`tester.bat`(务必以 ANSI 格式保存,否则中文乱码)]
```batch line-numbers```bat line-numbers@echo off:: 关闭命令回显chcp 936 >nul:: 设置活动代码页以防乱码(>nul 隐藏命令输出)3 行未改动:: max_cnt:对拍次数
:loopif %cnt% equ %max_cnt% ( pause goto :eof pause goto :eof)
set /a cnt+=1gen.exe %cnt% -1000000000 1000000000 >data.in7 行未改动fc /w std.out test.out >nul 2>&1:: 比较两个输出(2>&1 隐藏命令错误信息):: /w 过滤多余空白字符进行比较(但是这不完全等同于 OJ 的判题规则,有需要可自写比较逻辑)if %errorlevel% equ 1 ( echo 第 %cnt% 组测试 WA! pause goto :eof echo 第 %cnt% 组测试 WA! pause goto :eof):: 两个输出不一致,中止对拍(出错的数据可在文件中查看)
echo 第 %cnt% 组测试 AC!8 行未改动#include <bits/stdc++.h>using namespace std;
int main() { int max_cnt = 20; for(int i = 1; i <= max_cnt; i++) { system(("gen.exe " + to_string(i) + " -1000000000 1000000000 >data.in").c_str()); // 注意,system 传入的是 C 风格字符串,string 需转化 system("std.exe <data.in >std.out"); system("test.exe <data.in >test.out"); int code = system("fc /w std.out test.out >nul 2>&1"); if(code == 1) { cout << "第 " << i << " 组测试 WA!" << "\n"; return 0; } cout << "第" << i << " 组测试 AC!" << "\n"; } return 0; int max_cnt = 20; for(int i = 1; i <= max_cnt; i++) { system(("gen.exe " + to_string(i) + " -1000000000 1000000000 >data.in").c_str()); // 注意,system 传入的是 C 风格字符串,string 需转化 system("std.exe <data.in >std.out"); system("test.exe <data.in >test.out"); int code = system("fc /w std.out test.out >nul 2>&1"); if(code == 1) { cout << "第 " << i << " 组测试 WA!" << "\n"; return 0; } cout << "第" << i << " 组测试 AC!" << "\n"; } return 0;}```
:::27 行未改动#include <bits/stdc++.h>using namespace std;mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());long long rand_ll(long long l, long long r) { return uniform_int_distribution<long long>(l, r)(gen); return uniform_int_distribution<long long>(l, r)(gen);}
// 编译后命令行输入 gen.exe <测试点编号> 以运行int main(int argc, char* argv[]) { int id = atoi(argv[1]); if(id >= 1 && id <= 2) // 较小的正数据 cout << rand_ll(1, 1e4) << " " << rand_ll(1, 1e4) << "\n"; else if(id >= 3 && id <= 4) // 较小的数据 cout << rand_ll(-1e4, 1e4) << " " << rand_ll(-1e4, 1e4) << "\n"; else if(id >= 5 && id <= 6) // 较大的正数据 cout << rand_ll(1e6, 1e9) << " " << rand_ll(1e6, 1e9) << "\n"; else if(id >= 7 && id <= 9) // 随机数据 cout << rand_ll(-1e9, 1e9) << " " << rand_ll(-1e9, 1e9) << "\n"; else if(id == 10) // 极大边界数据 cout << "1000000000 1000000000" << "\n"; return 0; int id = atoi(argv[1]); if(id >= 1 && id <= 2) // 较小的正数据 cout << rand_ll(1, 1e4) << " " << rand_ll(1, 1e4) << "\n"; else if(id >= 3 && id <= 4) // 较小的数据 cout << rand_ll(-1e4, 1e4) << " " << rand_ll(-1e4, 1e4) << "\n"; else if(id >= 5 && id <= 6) // 较大的正数据 cout << rand_ll(1e6, 1e9) << " " << rand_ll(1e6, 1e9) << "\n"; else if(id >= 7 && id <= 9) // 随机数据 cout << rand_ll(-1e9, 1e9) << " " << rand_ll(-1e9, 1e9) << "\n"; else if(id == 10) // 极大边界数据 cout << "1000000000 1000000000" << "\n"; return 0;}```
:::10 行未改动set max_cnt=10
:loopif %cnt% equ %max_cnt% ( pause goto :eof pause goto :eof)
set /a cnt+=1gen.exe %cnt% >sum%cnt%.in64 行未改动set cnt=0:loopset /a cnt+=1if not exist data\sum%cnt%.in ( pause goto :eof pause goto :eof)::自动检查文件存在性
sum.exe <data\sum%cnt%.in >data\sum%cnt%.outfc /w data\sum%cnt%.out data\sum%cnt%.ans >nul 2>&1
if %errorlevel% equ 0 ( echo 第 %cnt% 组数据 AC! echo 第 %cnt% 组数据 AC!) else ( echo 第 %cnt% 组数据 WA! echo 第 %cnt% 组数据 WA!)goto loop```
4 行未改动```cpp line-numbers#include <bits/stdc++.h>using namespace std;
// 去除字符串末尾空白string rtrim(string s) { size_t end = s.find_last_not_of(" \t\r\n"); return end == string::npos ? "" : s.substr(0, end + 1);}
// 比较逻辑(此处写的是忽略行末空白比较,也可自写比较逻辑,或直接调用 fc)bool check(string out, string ans) { ifstream fout(out), fans(ans); if (!fout || !fans) return 0;
string lineo, linea; while (getline(fout, lineo) && getline(fans, linea)) if (rtrim(lineo) != rtrim(linea)) return 0; // 检查是否同时到达文件末尾 return fout.eof() && fans.eof();}
int main() { for (int i = 1; ; i++) { string in = "data/sum" + to_string(i) + ".in"; string out = "data/sum" + to_string(i) + ".out";3 行未改动 if (!test) break; test.close();
system(("sum.exe <" + in + " >" + out).c_str()); if (check(out, ans)) int code = system(("fc /w " + out + " " + ans).c_str()); if (code == 1) cout << "第 " << i << "组数据 AC!" << "\n"; else cout << "第 " << i << "组数据 WA!" << "\n"; }23 行未改动