I do not like to play the game when making data. Often written after a test sample, by the way! The sample is on the right, the cross! ----- WA is heard to cry out ┭┮﹏┭┮, so start looking for bad data, looking for bug. . .
Today I learned on white shot program, after some of the topics you can use this friends hee hee.
Learn two methods, one is more familiar with the previous redirected to a file, but that might forget to delete redirected out of direct cross-wa vain; the other is a batch file that looks like a more advanced way, The following two are served to introduce.
First, redirected to a file
Violence first to write code baoli.cpp (The answer must be right) and their own code youxiu.cpp
baoli.cpp重定向 freopen("data.in","r",stdin);
freopen("baoli.out","w",stdout);
1 #include <iostream> 2 #include<cstdio> 3 using namespace std; 4 5 int main(int argc, char** argv) { 6 freopen("data.in","r",stdin); 7 freopen("baoli.out","w",stdout); 8 int n; 9 cin>>n; 10 int ans=0; 11 for(int i=1;i<=n;i++) ans+=i; 12 cout<<ans<<endl; 13 return 0; 14 }
youxiu.cpp重定向 freopen("data.in","r",stdin);
freopen("youxiu.out","w",stdout);
1 #include <iostream> 2 #include<cstdio> 3 using namespace std; 4 5 int main(int argc, char** argv) { 6 freopen("data.in","r",stdin); 7 freopen("youxiu.out","w",stdout); 8 int n; 9 cin>>n; 10 cout<<n*(n+1)/2<<endl; 11 return 0; 12 }
Generating a data write rand.cpp
1 #include <iostream> 2 #include<cstdlib> 3 #include<ctime> 4 #include<sstream> 5 #define randint(l,r) ((l)+rand()%((r)-(l)+1)) 6 using namespace std; 7 int main(int argc, char** argv) { 8 int seed=time(NULL); 9 if(argc>1){ //如果有参数 10 stringstream ss; 11 ss.clear(); 12 ss << argv[1]; 13 is SS >> SEED; // convert integer to parameter into SEED 14 } 15 srand (SEED); 16 // above initializing a random number, do not modify . 17 The freopen ( " data.in. " , " W " , stdout ); 18 is int n-; . 19 n-= . 1 + RAND (%) 10000 ; // randomly generates a natural number of from 1 to 10,000 20 is COUT n-<< << endl; 21 is return 0 ; 22 is }
Write one pair beat the program, and then run on the line (before the .cpp To save and run)
1 #include<cstdio> 2 #include<iostream>#define File(name) freopen(name".in","r",stdin); freopen(name".out","w",stdout); 3 using namespace std; 4 5 inline int read(); 6 int main() 7 { 8 int s=0; 9 while(1) 10 { 11 system("rand.exe"); 12 system("youxiu.exe"); 13 system("baoli.exe"); 14 cout<<"here"<<endl; 15 if(system("fc youxiu.out baoli.out")) 16 system("pause"); 17 else 18 cout<<++s<<endl; 19 } 20 return 0; 21 }
Reference a blog, can not read can see here: https: //www.cnblogs.com/SeanOcean/p/10975527.html
Second, the batch file
This is even simpler matter.
Violence write their own code and the code baoli.cpp youxiu.cpp, do not add the redirect, normal write.
Write generate data files.
1 #include <iostream> 2 #include<cstdlib> 3 #include<ctime> 4 #include<sstream> 5 #define randint(l,r) ((l)+rand()%((r)-(l)+1)) 6 using namespace std; 7 int main(int argc, char** argv) { 8 int seed=time(NULL); 9 if(argc>1){ //如果有参数 10 std::stringstream ss; 11 ss.clear(); 12 ss << argv[1]; 13 is SS >> SEED; 14 } 15 srand (SEED); // convert integer to parameter into SEED 16 @ or more random number initialization, do not modify the 17 @ about its own generated random number 18 is int n- ; . 19 n-= . 1 + RAND ()% 10000 ; // randomly generates a natural number of from 1 to 10,000 20 is COUT n-<< << endl; 21 is return 0 ; 22 is }
Then write a batch file. How new it? Txt text file to direct the new suffix to .bat on the line. Right-editor, written on the inside.
Directly on the code:
1 @echo off 2 :loop 3 rand.exe %random% > data.in 4 baoli.exe < data.in > baoli.out 5 youxiu.exe < data.in > youxiu.out 6 fc baoli.out youxiu.out 7 if not errorlevel 1 goto loop 8 pause 9 goto loop
Very easy to understand, I do not understand it does not matter, will be used on the line. Here is a blog explained very clearly, you can take a look at: https://blog.csdn.net/wlx65003/article/details/51149196
So far two of the shoot is over. Personal feeling is more like a second hh