对拍机
C++#include<bits/stdc++.h>
#include<windows.h>
#define RE -1073741819
#define TLE 259
#define OK 0
#define FE -1
using namespace std;
string Force[105];
string Gen, Ans, Dir;
int n, tlim, t;
int Work(string exe, string in) {
STARTUPINFO si = { sizeof(STARTUPINFO) };//在产生子进程时,子进程的窗口相关信息
PROCESS_INFORMATION pi; //子进程的ID/线程相关信息
DWORD returnCode;//用于保存子程进的返回值;
string commandLine1 = (exe + " " + in + " out.out"); //测试命令行参数一
char t[100];
strcpy(t, commandLine1.c_str());
BOOL bRet = CreateProcess( //调用失败,返回0;调用成功返回非0;
NULL, //一般都是空;(另一种批处理情况:此参数指定"cmd.exe",下一个命令行参数 "/c otherBatFile")
t, //命令行参数
NULL, //_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
NULL, //_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
FALSE, //_In_ BOOL bInheritHandles,
CREATE_NEW_CONSOLE, //新的进程使用新的窗口。
NULL, //_In_opt_ LPVOID lpEnvironment,
NULL, //_In_opt_ LPCTSTR lpCurrentDirectory,
&si, //_In_ LPSTARTUPINFO lpStartupInfo,
&pi); //_Out_ LPPROCESS_INFORMATION lpProcessInformation
if (bRet) {
//等待子进程结束
WaitForSingleObject(pi.hProcess, tlim);//时间限制
//获取子进程的返回值
GetExitCodeProcess(pi.hProcess, &returnCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return returnCode;
}
else
return -1;
}
int main() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout << "▁▂▃▅▆▇Ψ§hzy 对拍器 1.6 Release 2§Ψ▇▆▅▃▂▁" << endl;
cout << "输入程序数量:";
cin >> n;
cout << "数据组数:";
cin >> t;
cout << "依次输入程序名:";
for(int i = 1;i <= n;i ++)cin >> Force[i];
int cnt = 1;
while(t --) {
cout << "-=TEST #" << cnt << "=-" << endl;
cout << "时间限制/ms :";
cin >> tlim;
string input, output;
cout << "输入文件: ";
cin >> input;
cout << "答案文件:";
cin >> output;
for(int i = 1;i <= n;i ++) {
cout << "SRC #" << i << " ";
int ans = Work(Force[i], input);
if(ans == OK) {
system(("fc out.out " + output + ">null.out").c_str());
ifstream fin("null.out");
string t;
while(fin >> t)
if( t == "找不到差异") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xaf),
cout << "√AC!√" << endl;
break;
}
if(t != "找不到差异")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0xcf), cout << "×WA×" << endl;
}
else {
if(ans == TLE) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6 * 16 + 15), cout << "■TLE■" << endl;
else if(ans == FE) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1 * 16 +15), cout << "□FE□" << endl;
else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5 * 16 + 15), cout << "◇RE◇" << endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
}
cnt ++;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
return 0;
}