对拍

新生赛D题贪心一直WA而又debug不出来,只能用对拍拍一下子
对拍的基本思路:有正确程序/小范围正确程序right.cpp, 你的WA程序wrong.cpp, 随机数生成测试的程序test.cpp三个程序
test.cpp:
srand(time(0)) 首先选定时间作为随机数种子
然后用随机数生成序列

#include <bits/stdc++.h>
using namespace std;
int main () {
	srand(time(0));
	printf("10\n");
		printf("%d 0\n", rand() * rand() % 100000 + 1) ;
		printf("0 %d\n", rand() * rand() % 100000 + 1) ;
	for (int i = 1; i <= 8; i ++) {
		printf("%d %d\n", rand() * rand() % 100000 + 1, rand() * rand() % 100000 + 1);
	} 
	return 0;
}

RAND_MAX至少为32767,如果担心不够大可以再乘一个。
然后把三个程序放到同一个文件夹里面,新建三个txt,
建立一个txt,内容如下:

g++ test.cpp -o test -g
g++ right.cpp -o right -g
g++ wrong.cpp -o wrong-g
:loop
	test.exe >1.txt
	right.exe<1.txt>2.txt
	wrong.exe<1.txt>3.txt
	fc 2.txt 3.txt
if not errorlevel 1 goto loop
pause
goto loop

前三行是对程序的编译
后面是循环比较right.cpp , wrong.cpp的输出2.txt,3.txt, 如果没有区别就会继续循环,否则就会停止,停止时就可以观察比较结果的不同。
把这个txt文件拓展名改为.bat脚本文件,就可以运行了。

本文作者:misasteria

本文链接:https://www.cnblogs.com/misasteria/p/16243939.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   misasteria  阅读(230)  评论(0编辑  收藏  举报
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起