实现对拍
总体:
对拍是一种适用于所有选手的一种验证错误的方法,可以用这种方法来实现错误与否。
可分为4个源代码。
我们用个A+Bproblem举例
自己的代码:
1 2 3 4 5 6 7 8 | #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; } |
暴力的代码:
1 2 3 4 5 6 7 8 9 | #include<iostream> using namespace std; int main() { int a,b,c; cin>>a>>b; c=a+b; cout<<c; } |
接下来是随机数生成器
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <ctime> #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main() { srand(time(0)); int a = rand()%0217; int b = rand()%1112; printf( "%d %d" ,a,b); return 0; } |
最后是对拍程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <windows.h> #include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main() { int T = 1000; while (T--) { system( "randdata > try.in" ); system( "try1 < try.in > try1.out" ); system( "try2 < try.in > try2.out" ); if (system( "fc try1.out try2.out" )) break ; } system( "pause" ); return 0; } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步