码了一晚上才码出这个,有点简陋,待更新
注意:1、数据路径自己在代码中修改,直接重定向即可
2、要配置好环境,将cb安装路径里的MinGW\bin路径放到path中
#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); Run(TOread); puts(""); Sleep(2000);//停止2s,让文件进行读取 printf("请输入测试代码1地址:"); scanf("%s", TOcode1); Change(TOcode1); Run(TOcode1); puts(""); Sleep(2000);//停止2s,让文件进行读取 printf("请输入测试代码2地址:"); scanf("%s", TOcode2); Change(TOcode2); Run(TOcode2); puts(""); Sleep(2000);//停止2s,让文件进行读取 int flag = CMP(); if (flag == -1) { puts("Invalid address, please check your address\n"); } else if (flag == 1) { puts("answer is right\n"); } else { puts("answer is wrong"); } return 0; }
时间: 2024-10-12 12:48:30