#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("data.out","r",stdin);
freopen("test.out","w",stdout);
int i,n;
long int sum = 0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=i;
}
printf("%d\n",sum);
return 0;
}
而std.cpp里的代码是:
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("data.out","r",stdin);
freopen("std.out","w",stdout);
int n;
long long sum = 0;
scanf("%d",&n);
sum=n*(n+1)/2;
printf("%d\n",sum);
return 0;
}
那你rand.cpp就这么写:
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("data.out","w",stdout);
srand(time(NULL));
int a=rand()%10000+1;
printf("%d\n",a);
return 0;
}
然后编译成rand.exe
最后运行 对拍程序 等待结果即可,如果拍不上程序会自动暂停下来,这个时候就可以开始写下一题了~~~
对拍.cpp 的代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long i=0;
while(1)
{
printf("The result of No. %d Case is: ",++i);
system("data.exe > data.txt");
system("std.exe < data.txt > std.txt");
system("test.exe < data.txt > test.txt");
if (system("diff std.out test.out"))//比较程序的输出
{
puts("WA");
return 0;
}
else puts("AC");
}
return 0;
}
如果你还想看看自己的算法快了多少,对拍.cpp 可以这么写:
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long i=0,s,t;
while(1)
{
printf("The result of No. %d Case is: ",++i);
system("data.exe > data.txt");
s=clock();//测试时间
system("std.exe < data.txt > std.txt");
t=clock();
system("test.exe < data.txt > test.txt");
if(system("diff std.out test.out"))
{
puts("WA");
return 0;
}
else puts("AC");
printf("Save %d millisecond\n",t-s);
}
return 0;
}
如果是在Ubantu下运行对拍,代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i=0;
while(1)
{
system("./make");
system("./gcd");
system("./gcdBL");
if(system("diff gcd.out gcdBL.out -w")) return puts("WA"),0;
else printf("Is %d : AC\n",++i);
}
}