碼了一晚上才碼出這個,有點簡陋,待更新
注意:1、數據路徑自己在代碼中修改,直接重定向即可
? ? ? ? ?2、要配置好環境,將cb安裝路徑里的MinGW\bin路徑放到path中
3、三份代碼記得先編譯一遍,再運行這份代碼
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <string> #include <stack> #include <map> #include <set> #include <bitset> #include <windows.h> #define X first #define Y second #define clr(u,v); memset(u,v,sizeof(u)); #define in() freopen("data","r",stdin); #define out() freopen("ans","w",stdout); #define Clear(Q); while (!Q.empty()) Q.pop(); #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 1e5 + 10; const int INF = 0x3f3f3f3f; void getbat(char* TO) {FILE *fp = fopen("open.bat", "w");fprintf(fp, "cd %s\n", TO);fprintf(fp, "c++ main.cpp\n");fprintf(fp, "a.exe\n");fclose(fp); }void Run(char* TO)//運行代碼 {getbat(TO);ShellExecute(NULL, "open", "open.bat", NULL, NULL, SW_SHOWNORMAL); }void Change(char *s) {int len = strlen(s);for (int i = 0; i < len; i++)if (s[i] == '\\')s[i] = '/'; } char str1[maxn], str2[maxn]; int CMP() {FILE *fp1 = fopen("C:/Users/shuhan/Desktop/ans1", "r"), *fp2 = fopen("C:/Users/shuhan/Desktop/ans2", "r");if (fp1 == NULL || fp2 == NULL){puts("NO this file\n");return -1;}while ((fgets(str1, INF, fp1) != NULL) | (fgets(str2, INF, fp2) != NULL)){if (strcmp(str1, str2) != 0){puts("error !");puts("data1 is :");puts(strcmp(str1, "") == 0 ? "NULL" : str1);puts("but data2 is :");puts(strcmp(str2, "") == 0 ? "NULL" : str2);fclose(fp1);fclose(fp2);return 0;}}puts("ok!");fclose(fp1);fclose(fp2);return 1; }char TOread[100], TOcode1[100], TOcode2[100]; int main() {printf("請輸入輸入代碼地址:");scanf("%s", TOread);Change(TOread);puts("");printf("請輸入測試代碼1地址:");scanf("%s", TOcode1);Change(TOcode1);puts("");printf("請輸入測試代碼2地址:");scanf("%s", TOcode2);Change(TOcode2);puts("");int Case = 1;int T=INF;//設置執行次數int Time = 2000;//等待時間,不建議太短do{printf("Case %d: ",Case++);Run(TOread);Sleep(Time);//停止2s,讓文件進行讀取 Run(TOcode1);Sleep(Time);//停止2s,讓文件進行讀取 Run(TOcode2);Sleep(Time);//停止2s,讓文件進行讀取int flag = CMP();if (flag == -1){puts("Invalid address, please check your address\n");break;}else if (flag == 1){puts("answer is right\n");}else{puts("answer is wrong");break;}} while (T--);return 0; }
?