#include<bits/stdc++.h>
using namespace std;
const int AllThrCnt = 1e4, SinThrCnt = 1;
auto sysrun(string str){
return system(str.c_str());
}
enum judgeinfo{J_AC, J_RE, J_WA};
judgeinfo run(string sdata, string sfa, string sfb,int id){
string sin = to_string(id) + ".in";
string soa = to_string(id) + ".out";
string sob = to_string(id) + ".ans";
string comdata = "./" + sdata + ">" + sin;
string coma = "./" + sfa + "<" + sin + ">" + soa;
string comb = "./" + sfb + "<" + sin + ">" + sob;
string comdiff = "diff -Z " + soa + " " + sob + " >/dev/null";
// cout <<comdata << endl;
// cout << coma <<endl;
// cout << comb << endl;
// cout << comdiff << endl;
sysrun(comdata);
if(sysrun(coma)) {
return J_RE;
}
if(sysrun(comb)){
return J_RE;
}
if(sysrun(comdiff)){
return J_WA;
}
return J_AC;
}
judgeinfo res[AllThrCnt];
void thrrun(string sdata, string sfa, string sfb, int id){
judgeinfo ret = run(sdata, sfa, sfb, id);
res[id] = ret;
}
string make_string(judgeinfo res){
if(res == J_AC) return "AC";
else if(res == J_RE) return "RE";
else if(res == J_WA) return "WA";
return "UKE";
}
bool makeround(int rndcnt, string sdata, string sfa, string sfb){
vector<thread> v;
for(int i = 0; i < rndcnt; ++i){
v.push_back(thread(thrrun, sdata, sfa, sfb, i));
}
for(auto &it : v){
it.join();
}
for(int i = 0; i < rndcnt; ++i){
if(J_AC != res[i]){
cout << make_string(res[i]) <<" " << i << endl;
return false;
}
}
return true;
}
void clear_file(int rndcnt){
for(int i = 0; i < rndcnt; ++i){
string comb = "rm " + to_string(i);
fstream f((to_string(i) + ".in").c_str());
if(!f) break;
sysrun(comb + ".in");
sysrun(comb + ".out");
sysrun(comb + ".ans");
}
}
int main(){
clear_file(AllThrCnt);
int judcnt = 1;
string sfa = "a";
string sfb = "b";
string sdata = "data";
int tot = 0;
for(; tot + SinThrCnt<= judcnt; tot += SinThrCnt){
cout <<"Running good" << tot << endl;
if(makeround(SinThrCnt, sdata, sfa, sfb) == false){
return 0;
}
}
for(; tot + SinThrCnt<= judcnt; tot += SinThrCnt){
cout <<"Running good" << tot << endl;
if(makeround(1, sdata, sfa, sfb) == false){
return 0;
}
}
clear_file(SinThrCnt);
return 0;
}
标签:soa,sob,string,sdata,int,多线程,id
From: https://www.cnblogs.com/cdsidi/p/17128477.html