Linux/Ubuntu系統對拍程序

輸出兩文件結果的差異和輸入的文件(基於Linux的命令,僅適用於Linux)
樣式爲

1                       1		 //左邊爲my.out 右邊爲text.out,並行輸出,將指令'-y -W 50'修改爲'-c'可改爲豎直輸出
2                     | 1        //其中的|號爲差異點,無|的爲相同的
input:					     //輸出input.in文件																		           
1
904532930303613184

WA

對拍程序battle.cpp

#include<cstdio>
#include<cstdlib>
using namespace std;

int main()
{
    int i=0;
    while(1){
        system("./data");
        system("./my");
        system("./text");
        printf("%d : ",i++);
        if (system("diff my.out text.out")){
            printf("\n\ncompare:\n");
            system("diff my.out text.out -y -W 50");
            printf("\n\ninput:\n");
            system("cat input.in");
            printf("\nWA\n");
            return 0;
        }
        else printf("AC\n");
    }
    return 0;
}

數據文件data.cpp

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<ctime>
using namespace std;

const long long MOD=1e18;

int main()
{
    // cout<<RAND_MAX<<endl;
    freopen("input.in","w",stdout);
    srand(time(NULL));
    int t=1;
    cout<<t<<endl;
    while(t--){
        long long n=(long long )((double)(1.0*rand()*MOD)/RAND_MAX);
        cout<<n<<endl;
    }
    
    return 0;
}

正確程序或暴力程序text.cpp

#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("input.in","r",stdin);
    freopen("text.out","w",stdout);
    return 0;
}

自己程序my.cpp

#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("input.in","r",stdin);
    freopen("my.out","w",stdout);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章