Program to beat

tar-add:

#include <stdio.h>

int main ()
{
    int a,b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a+b);

    return 0;
}

totar-add2:

#include <stdio.h>

int main ()
{
    int a,b;
    scanf("%d %d",&a, &b);
    while(b--) 
    {
        a++;
    }

    printf("%d\n", a);

    return 0;
}

 

The so-called "on the beat", as the name suggests, is to make the two are compared. The so-called "two", first you want to test the program -tar, the second is an answer in the program within a certain range (time / space) must be the result of the correct procedures -totar (generally used violence to solve the program).

Both programs compiled after ready, we are ready to use the test input sample. But if the input sample preparation up man, then certainly a waste of time but also costs the brain, not to mention at the time of the race. The human brain unreliable, then rely on computers.

To give a more comprehensive test sample, we can use a pseudo random number. See Into STL article.

 

In order to repeatedly beat and beat on the similarities and differences between treatment program output, we need a program that can be given to shoot at a given frequency, and the outcome does not stop at the same time. Need to use this header file when writing this program:

#include <windows.h>

 

 

To shoot program

#include <stdio.h>
#include <windows.h>
using namespace std;

int main ()
{
    int cnt = 100;

    while(cnt--)
    {
        system("g++ data.cpp -o data");     
        system("data > a+b.in");            
        system("g++ add.cpp -o add");
        system("add < a+b.in > add.out");     
        system("g++ add2.cpp -o add2"); 
        system("add2 < a+b.in > add2.out");

        if(system("fc add.out add2.out"))     
        {
            break;
        }
    }

    system("pause");

    return 0;
}

Run the file to

 

Guess you like

Origin www.cnblogs.com/lightworkshopnoi/p/11368487.html