windows下的对拍用小玩意

  1 #include <cstdio>
  2 #include <fstream>
  3 #include <iostream>
  4 
  5 #include <cstdlib>
  6 #include <cmath>
  7 #include <cstring>
  8 #include <algorithm>
  9 
 10 typedef long long int ll;
 11 typedef double db;
 12 
 13 #define DBG printf("*")
 14 
 15 using namespace std;
 16 
 17 int opt,ods;
 18 char c[10000000]; //accept less than 9.5M file
 19 char s[10000000];
 20 int ap,sp;
 21 
 22 int main()
 23 {
 24     //printf("output situation?\n");
 25     //scanf("%d",&opt);
 26     opt=1;
 27     if(opt)
 28     {
 29         printf("output details?\n");
 30         scanf("%d",&ods);
 31     }
 32     
 33     int T;
 34     printf("times tested:\n");
 35     scanf("%d",&T);
 36     
 37     int tot=0;
 38     
 39     bool checked=true;
 40     int kc,ks;
 41     int tg=0,tx=0,ty=0; int dt=0;
 42         
 43     do
 44     {
 45         int T=clock();
 46         if(system("G.exe")){ printf("genurator broke! exit."); return 0; }
 47         dt=clock()-T;
 48         if(opt) printf("gen run out. time use:%dms.\n",dt);
 49         tg+=dt;
 50         
 51         
 52         //read program a
 53         T=clock();
 54         if(system("x.exe")){ printf("x broke! exit."); return 0; }
 55         dt=clock()-T;
 56         if(opt) printf("x run out. time use:%dms.\n",dt);
 57         tx+=dt;
 58         
 59         freopen("out.txt","r",stdin);
 60         ap=0;
 61         while(!feof(stdin)) c[ap++]=getchar();
 62         fclose(stdin);
 63         
 64         //read program b
 65         T=clock();
 66         if(system("y.exe")){ printf("y broke! exit."); return 0; }
 67         dt=clock()-T;
 68         if(opt) printf("y run out. time use:%dms.\n",dt);
 69         ty+=dt;
 70         
 71         freopen("out.txt","r",stdin);
 72         sp=0;
 73         while(!feof(stdin)) s[sp++]=getchar();
 74         fclose(stdin);
 75         
 76         
 77         //compare
 78         if(opt) printf("start compare...\n");
 79         
 80         if(ods)
 81         {
 82             for(int i=0;i<min(10,ap);i++) cout<<c[i]; cout<<endl; 
 83             for(int i=0;i<min(10,sp);i++) cout<<s[i]; cout<<endl;
 84         }
 85         
 86         kc=0,ks=0;
 87         
 88         int it=0;
 89         while(kc!=ap || ks!=sp)
 90         {
 91             //ignore space and enter
 92             while(kc<ap && c[kc]==' ' || c[kc]=='\n' || s[ks]=='\r')
 93                 kc++;
 94             while(ks<sp && s[ks]==' ' || s[ks]=='\n' || s[ks]=='\r')
 95                 ks++;
 96             
 97             //if(it<5) { printf("%d %d\n",c[kc],s[ks]); }
 98             
 99             //compare
100             if(c[kc]!=s[ks]){ checked=false; break; }
101             kc++; ks++;
102             it++;
103         }
104         
105         if(opt) printf("check out!\n");
106         
107         tot++;
108         
109         if(!opt) { if(tot%10==0) printf("%d\n",tot); } 
110         else printf("==%d==\n",tot);
111     }
112     while(checked == true && tot<T);
113     
114     if(checked==false)
115     {
116         printf("checked failed.\nat the %d case.\nat charactor %d and %d.\ndatafile is in the folder.\n",tot,kc,ks);
117     }else
118     {
119         printf("check complete,no any wrong thing detacted.\nfor %d cases.\n",tot);
120         printf("generator used time:%.4fs (avg:%.4fms)\n",(db)tg/1000,(db)tg/tot);
121         printf("program x used time:%.4fs (avg:%.4fms)\n",(db)tx/1000,(db)tx/tot);
122         printf("program y used time:%.4fs (avg:%.4fms)\n",(db)ty/1000,(db)ty/tot);
123         printf("amount to:%.4fs (avg:%.4fms)\n",(db)clock()/1000,(db)clock()/tot);
124     }
125     
126     system("PAUSE");
127     
128     return 0;
129 }
View Code

 

posted @ 2015-01-14 20:00  DragoonKiller  阅读(145)  评论(0编辑  收藏  举报