需要用到的有三个部分(同一目录下)
在Windows下可用,Linux 下请使用其他方案
1.比较程序 duipai.cpp编译→duipai.exe
内容如下,是固定的,不需要修改:
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
while(1){
system("data.exe > in.txt");
system("std.exe < in.txt > stdout.txt");
system("test.exe < in.txt > ans.txt");
if(system("fc stdout.txt ans.txt")){
return 1;
}
}
}
2.标准答案程序 std.cpp编译→std.exe
这里的内容是暴力搜索答案,或者是其他通过的代码(标程)
注意:有无限输入(while(cin>>n>>m)){}的话在末尾加上 break;
3.自己的未通过代码 test.cpp编译→test.exe
写入自己的未通过代码,注意:同样有无限输入(while(cin>>n>>m)){}的话在末尾加上 break;
4.输入的数据生成 data.cpp编译→data.exe
基础内容:
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
srand((int)time(0));
//数据区:自由修改
cout<<"1"<<endl;
cout<<"100 3"<<endl;
// 生成方式选择
//
return 0;
}
所需要的功能性添加:
不重复数字随机序列(一行+一个换行)
vector<int> temp;
for (int i = 0; i < 16; ++i)
{
temp.push_back(i+1);
}
random_shuffle(temp.begin(), temp.end());
for (int i = 0; i < temp.size(); i++)
{
cout << temp[i] << " ";
}
cout<<endl;
随机数字序列(一行+一个换行)
for (int i = 0; i < 100; ++i)
{
printf("%d ",rand()%20+1);
//有加一代表是是正整数,否则是自然数
}
编译并运行查看是否符合题目数据规范
确保4个文件都已经编译
运行duipai.exe弹出窗口
如果一直是上图这样,系统不关闭窗口,说明结果相同,需要更改data.cpp加大数据强度,编译再运行duipai.exe。
如果窗口突然关闭则说明在in.txt下标程std.exe输出stdout.txt和你的程序test.exe输出的ans.txt不同,也就是这组输入数据in.txt需要debug
以下是源文件和生成的文件目录: