windows和linux下如何对拍
对拍是各种计算机考试检查时必备工具,实际上十分强大,只要你的暴力没有写错就没有问题。 对拍的意思:(怎么有点语文课的意思雾) 对:看见‘对’就可以知道有两个。 拍:就是把两个程序结果拍在一起,对照(有点牵强)。 实践由于Windows和Linux系统不同,平常大多数人都用Windows,而在noi系列赛事中都采用Linux系统。 Windows就以a+b为例吧。 首先摆一个可能是正解的东西。 #include<cstdio> #include<windows.h> #include<ctime> #include<cstdlib> using namespace std; int main() { int a,b; scanf("%d%d",&a,&b); for(int i=1;i<=n;i++)a++,b--; printf("%dn",a+b); return 0; } 现在摆一个一定是正确的但时间和内存超标的代码,当然例子没有超标。 #include<cstdio> using namespace std; int main() { int a,&b); printf("%dn",a+b); return 0; } 构造数据。 注意不能只用rand构造,因为rand表示伪随机数,在一定基数下一定,所以用rand构造的随机数出题人也知道你构造的是什么(然后故意卡你) 所以介绍一个新东西。 #include<ctime> 这个怎么用??? srand(time(NULL)); 这个时候,他的随机数随时间变化(笑),出题人再也搞不出来卡你的算法了; #include<cstdio> #include<ctime> #include<cstdlib> using namespace std; int main() { srand(time(NULL)); printf("%d %dn",rand()%1000,rand()%1000); } 注意换行符必须加,否则你想想手动输入数据不加换行会怎么样。 下面的就是对拍程序: #include<stdio.h> #include<time.h> #include<windows.h> using namespace std; int main() { int t=1000;//如果不是自己电脑可以无限调大,不过要悠着点(笑) while(t!=0) { clock_t t1,t2;//设时间 system("data.exe>data.txt");//把data文件转化成txt格式 t1=clock(); system("1.exe<data.txt>1.txt");//把1文件搜如data.txt然后转化成1.txt t2=clock()-t1; system("2.exe<data.txt>2.txt");//把2文件搜如data.txt然后转化成2.txt printf("time=%dmsn",t2);//计算时间,可能会大一些 if(system("fc 1.txt 2.txt"))break;//比较1.txt与2.txt不同就跳出 t--; } if(t==0)printf("no errorn"); else printf("errorn"); getchar(); return 0; } 程序运行。 如果程序出错就在生成的txt文件里找样例: data.txt里是样例。1.txt和2.txt是输出。 Linux系统这个系统是我不经常接触的(实际上只在考试接触),所以如有口胡请见谅,请指出。 还是a+b。(其实Windows也可以这么搞) #include<cstdio> using namespace std; int main() { freopen("add.in","r",stdin); freopen("add.out","w",stdout); int a,a+b); return 0; } 暴力: 文件名:2.cpp #include<cstdio> using namespace std; int main() { freopen("add.in",stdin); freopen("add1.out",a+b); return 0; } 造数据: 文件名:data.cpp #include<cstdio> #include<ctime> #include<cstdlib> using namespace std; int main() { freopen("add.in",stdout); srand(time(NULL)); printf("%d %dn",rand()%1000); } 对拍: 文件名:duipai.cpp #include<bits/stdc++.h>//由于windows.h库在Linux下不可用,我也不知道system应调用什么文件,就用万能头文件233. using namespace std; int main() { int t=10; while(t!=0) { clock_t t1,t2; system("./data");//打开data t1=clock(); system("./1");//打开文件1 t2=clock()-t1; system("./2");//打开文件2 printf("time=%dmsn",t2); if(system("diff add.out add1.out"))break;//比较答案 t--; } if(t==0)printf("no errorn"); else printf("errorn"); getchar(); return 0; } 由于不善于用linux系统,所以没有留下图片,抱歉
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows-10 – 如何检测Windows 10上的开发者模式是否处于活
- windows-phone-7 – Windows phone 7 messageBox声音
- windows – 批量传真处理
- windows-mobile – Windows Mobile上的Java(ME)
- windows – Inno设置:使用{pf}在32位/ 64位系统上使用“Pr
- windows – 批处理文件,每1分钟执行一次命令
- 无法将证书添加到Windows 7中的受信任的根证书颁发机构
- Win10常用快捷键
- 在turbo pascal 5.5中的旧IBM PS / 2上读/写文件
- windows-server-2008 – 在VMware ESX上部署SQL Server 200
- windows-server-2008 – 新颖的eDirectory和Wind
- Windows FILETIME结构是否包含闰秒?
- 域登录 主机登录 远程登录
- windows-server-2012-r2-TLS 1.2 Windows Server
- Windows上的Git GUI:合并冲突
- windows – inno setup需要有关开始菜单下图标组
- winapi – 如何从使用“Project Centennial conv
- 使用IIS 7.5和Windows 7安装DotNetNuke 5.6.3时出
- windows – 强制终止进程时的进程退出代码
- windows – 拒绝目标文件夹访问 – 您需要获得执