diff

#include<bits/stdc++.h>
#include<sys/timeb.h>
#define del(x) " rm "<<(x)<<" "
#define make(x) " g++ "<<x<<".cpp "<<options<<x<<" "
#define ger(file) "./"<<file<<" > in"
#define exe(file,out) "./"<<file<<" < in > "<<out

using namespace std;

//-----------------------------------------
int t=1000,ktime=1000;
string data_gener="rand";
string your_code="a";
string std_or_bf="b";
string your_output="a.out";
string std_output="b.out";
vector<string> opt={
	"-Wall -O2 -std=c++14 ",
	// "-fsanitize=address ",
	// "-fsanitize=undefined ",
	// "-fsanitize=signed-integer-overflow ",
	"-o "
};
//you should modify this part to adapt your code
//----------------------------------------
int cnt;
string options="";
string e_rand,e_a,e_b,dif;
signed main(){
	stringstream ss;
	for(auto op:opt) options+=op;
	ss<<del(data_gener)<<";"<<del(your_code)<<";"<<del(std_or_bf)<<";"
		<<make(data_gener)<<"&&"<<make(your_code)<<"&&"<<make(std_or_bf);
	string bash=ss.str();
	// cout<<bash<<'\n';

	stringstream er;
	er<<ger(data_gener);
	e_rand=er.str();
	
	stringstream ea;
	ea<<exe(your_code,your_output);
	e_a=ea.str();

	stringstream eb;
	eb<<exe(std_or_bf,std_output);
	e_b=eb.str();

	stringstream df;
	df<<"diff -Z "<<your_output<<" "<<std_output;
	dif=df.str();
	// cout<<e_rand<<'\n'<<e_a<<'\n'<<e_b<<'\n'<<dif<<'\n';

	assert(!system(bash.c_str()));
	while(t--){
		printf("#%d------->", ++cnt);

		assert(!system(e_rand.c_str()));
		
		std::chrono::milliseconds mbs = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
		long long bgt=mbs.count();

		assert(!system(e_a.c_str()));

		std::chrono::milliseconds mes = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
		long long edt=mes.count();
		printf("time: %lld  ",edt-bgt);
		if(edt-bgt>ktime) return assert(!system("echo 'Time Limit Error'")), 0;
		
		assert(!system(e_b.c_str()));

		if(system(dif.c_str()))
			return assert(!system("echo 'Wrong Answer'")), 0;
		puts("Accepted");
	}
}
ori_ver
#include<bits/stdc++.h>
#include<sys/timeb.h>
using namespace std;
int t=1000,cnt,ktime=1000;
signed main(){
	system("rm rand; rm a; rm b; make rand && make a && make b"); 
	while(t--){
		printf("#%d------->", ++cnt);
		system("./rand > in");
		std::chrono::milliseconds mbs = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
		long long bgt=mbs.count();
		system("./a < in > a.out");
		std::chrono::milliseconds mes = std::chrono::duration_cast< std::chrono::milliseconds >(std::chrono::system_clock::now().time_since_epoch());
		long long edt=mes.count();
		// cout<<bgt<<' '<<edt<<'\n';
		printf("time: %lld  ",edt-bgt);
		if(edt-bgt>ktime) return system("echo 'Time Limit Error'"), 0;
		system("./b < in > b.out");
		if(system("diff -Z a.out b.out"))
			return system("echo 'Wrong Answer'"), 0;
		puts("Accepted");
	}
}
posted @ 2025-07-07 21:40  Gon-Tata  阅读(127)  评论(5)    收藏  举报