对拍

对拍

作用就不说了

怎么写呐?

首先需要一个库

 1 #include<windows.h> 

看这个库名就知道是干啥的了吧

system()调用cmd

用 fc 指令

fc 后面接两个文件可以比对两个文件是否相同或者比对大小

然后system()打开造数据的exe , 打开暴力exe跑一遍 , 然后打开自己的正解跑一遍

然后 fc 比较是否相同

也可以完善一下比如记录运行消耗的时间或者运行消耗的内存

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<ctime>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<windows.h>
 7 #define APART puts("----------------------")
 8 #define debug 1
 9 #define inf 100010
10 #define ll long long
11 #define MOD 998244353
12 #define INF 0x7fffffff
13 #define INF_T 9223372036854775807
14 #define DEBUG printf("%s %d\n",__FUNCTION__,__LINE__)
15 using namespace std;
16 
17 namespace chino{
18 
19 clock_t allb = 0;
20 clock_t alle = 0;
21 
22 clock_t totB;
23 clock_t totS;
24 
25 int ColorControlNum=14;
26 #define color Color_Change_CON
27 void Color_Change_CON(int n){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),n);}
28 void red(){color(4);}
29 void green(){color(10);}
30 void yellow(){color(14);}
31 void Qred(){color(12);}
32 void blue(){color(9);}
33 void Dblue(){color(1);}
34 void Qblue(){color(3);}
35 void white(){color(7);}
36 void Dgreen(){color(2);}
37 void WhiteBlue(){color(11);}
38 void n(){color(ColorControlNum);}
39 
40 int main(){
41     n();
42     puts("Input how many times do you want to check");
43     int T; cin >> T;
44     puts("Input the EXE file name :");
45     puts("Setting: default cmd code: \"fc afile_baoli afile_tmp\"\n");
46     int times = 0;
47     clock_t begin = 0, end = 0;
48     allb = clock();
49     for(int i = 1; i <= T; i++){
50         ++times;
51         begin = clock();
52         system("afile_makeDATA.exe");
53         end = clock();
54         printf("Making data uses");green();printf(" %d ", (int)(end - begin));n();puts("ms\n");
55         puts("Running the first code");
56         begin = clock();
57         system("afile_baoli.exe");
58         end = clock(); totB += (end - begin);
59         printf("Running the first code uses");green();printf(" %d ", (int)(end - begin));n();puts("ms\n");
60         puts("Running the second code");
61         begin = clock();
62         system("afile_tmp.exe");
63         end = clock(); totS += (end - begin);
64         printf("Running the second code uses");green();printf(" %d ", (int)(end - begin));n();puts("ms\n");
65         puts("");
66         if(system("fc _test.out _test.me.out")){
67             putchar(7);
68             red();printf("Error : times = %d\n",times);n();
69             puts("Opening the files");
70             system("start _test.in");
71             system("start _test.out");
72             system("start _test.me.out");
73             return 0;
74         } else green(),printf("Right : times = %d\n",times),n();
75         puts("\n");
76     }
77     alle = clock();
78     putchar(7);
79     puts("\n\n");
80     green();puts("All right!");n();
81     printf("using");green();printf(" %d ", (int)(alle - allb));n();puts("ms");
82     printf("\n\nbaoli time in total: %d ms. once time: %d ms\n", (int)totB, (int)totB / times);
83     printf("std(tmp) time in total: %d ms. once time: %d ms\n", (int)totS, (int)totS / times);
84     return 0;
85 }
86 
87 }//namespace chino
88 
89 int main(){return chino::main();}

 

posted @ 2019-10-05 12:49  ChiaroShiro  阅读(285)  评论(0编辑  收藏  举报