您的位置:首页 > 其它

ACM 程序对拍

2016-07-24 12:24 405 查看
1.首先是要有一个产生数的程序,将产生的数据保存在data.txt中。

产生int型小数

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<time.h>
int main() {
freopen("data.txt", "w", stdout);
srand(time(NULL));
//通过控制t的大小控制产生数的范围,控制n可以控制数据的产生量。
int t, n = 1000;
while(n--) {
printf("%d\n",rand()%t);
}
return 0;
}


产生随机的两位小数

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<time.h>
int main() {
freopen("data.txt", "w", stdout);
srand(time(NULL));
int n = 1000;
while(n--) {
printf("%.2lf\n",rand()*1.0/100);
}
return 0;
}


产生字符串

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<time.h>
int main() {
freopen("data.txt", "w", stdout);
srand(time(NULL));
int t, n = 1000;
while(n--) {
printf("%c\n",rand()%26 + 'A');
}
return 0;
}


相对于所需要的数据在这个基础上修改就可以了。

2.在你的程序与已经AC的程序上分别加上

freopen( "data.txt","r",stdin );
freopen( "1.txt","w",stdout );
freopen( "data.txt","r",stdin );
freopen( "2.txt","w",stdout );
为了方便查找不同的测试数据,建议把读入的数据一并输出,方便查看。

3.在保存数据的位置新建一个文本文档

内容是

fc out1.txt out2.txt 

pause
并把文本的扩展名改为.bat,点击运行就可以查看不同的测试数据了。
例如:

#include <stdio.h>
int main() {
freopen( "data.txt","r",stdin ); freopen( "1.txt","w",stdout );
int a, b;
while (scanf("%d%d", &a, &b) != EOF) {
printf("%d %d ", a, b);
printf("%d\n", a + a);
}
return 0;
}

#include <stdio.h>
int main() {
freopen( "data.txt","r",stdin ); freopen( "2.txt","w",stdout );
int a, b;
while (scanf("%d%d", &a, &b) != EOF) {
printf("%d %d ", a, b);
printf("%d\n", a + b);
}
return 0;
}


进行对拍会显示



显示不同的数据就可以拿来用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: