提供一个方便的工具供大家调试(一个伪数据生成器)
查看原帖
提供一个方便的工具供大家调试(一个伪数据生成器)
118006
Funny_ppt楼主2018/10/28 10:19
#include <bits/stdc++.h>
using namespace std;

struct weight
{
	char c;
	unsigned int w;
};
vector<weight> base_c={{'K',20},{'D',20},{'J',8},{'Z',2},{'W',10},{'N',10},{'P',4},{'F',6}};
unsigned int all;

void init_p()
{
	srand(time(0));
	all=0;
	for (auto ptr : base_c)
	{
		all+=ptr.w;
	}
}

char rand_card()
{
	if (all==0)init_p();
	unsigned int tmp=rand()%all,add=0;
	for (auto ptr=base_c.begin();ptr!=base_c.end();ptr++)
	{
		add+=ptr->w;
		if (tmp<=add)return ptr->c;
	}
}

int main ()
{
	unsigned int plnum=rand()%9+2,cards=rand()%20*100+40;
	ofstream testf("zgs_test.in",ios_base::out);//可以更改输出文件名
	testf<<plnum<<" "<<cards<<endl;
	testf<<"MP";
	for (int i=0;i<4;i++)testf<<" "<<rand_card();
	testf<<endl;
	for (int i=1;i<plnum;i++)
	{
		if (rand()%2)testf<<"ZP";
		else testf<<"FP";
		for (int i=0;i<4;i++)testf<<" "<<rand_card();
		testf<<endl;
	}
	for (int i=0;i<cards;i++)testf<<rand_card()<<" ";
	
	cout<<"Done!";
    testf.close();
	return 0;
}

建议搭配重定向实现全自动对拍

//我的对拍程序片段
	while (true)
	{
		system("zgs_generator.exe");
		Sleep(20);
		system("me.exe <zgs_test.in >zgs_test_me.out");
		system("ans.exe <zgs_test.in >zgs_test_ans.out");
		Sleep(100);
		if (!cmpfile("zgs_test_me.out","zgs_test_ans.out"))
		{
			cerr<<"Different Output!\n";
			cin.get();
		}
	}
2018/10/28 10:19
加载中...