鱼C论坛

 找回密码
 立即注册
查看: 2070|回复: 1

OJ评测

[复制链接]
发表于 2019-8-2 18:52:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
用C++做一个OJ,可以判断格式错误、正确、答案错误、时间超限,选手程序已经编译为user.exe文件。代码:
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<time.h>
  5. #include<windows.h>
  6. bool cmp(char answer[],char output[]) {
  7.         int apos=strlen(answer)-1,opos=strlen(output)-1;
  8.         while((answer[apos]=='\n'||answer[apos]==' ')&&apos!=0) apos--;
  9.         while((output[opos]=='\n'||output[opos]==' ')&&opos!=0) opos--;
  10.         while(apos!=0&&opos!=0) {
  11.                 while(answer[apos]==' '&&apos!=0) apos--;
  12.                 while(output[opos]==' '&&opos!=0) opos--;
  13.                 while(apos!=0&&opos!=0) {
  14.                         if(answer[apos]=='\n'&&output[opos]=='\n') {apos--,opos--;break;}
  15.                         if(!(answer[apos]!='\n'||output[opos]!='\n')) return 0;
  16.                         if(answer[apos]!=output[opos]) return 0;
  17.                         apos--,opos--;
  18.                 }
  19.         }
  20.         return !(apos^opos);
  21. }
  22. bool cmp2(char answer[],char output[]) {
  23.         int apos=strlen(answer)-1,opos=strlen(output)-1;
  24.         while(apos!=0&&opos!=0) {
  25.                 while((answer[apos]=='\n'||answer[apos]==' '||answer[apos]=='\t')&&apos!=0) apos--;
  26.                 while((output[opos]=='\n'||output[opos]==' '||output[opos]=='\t')&&opos!=0) opos--;
  27.                 if(answer[apos]!=output[opos]) return 0;
  28.                 apos--,opos--;
  29.         }
  30.         if(apos!=0) if(answer[apos-1]=='\n'||answer[apos-1]==' '||answer[apos-1]=='\t') apos--;
  31.         if(opos!=0) if(output[opos-1]=='\n'||output[opos-1]==' '||output[opos-1]=='\t') opos--;
  32.         while((answer[apos]=='\n'||answer[apos]==' '||answer[apos]=='\t')&&apos!=0) apos--;
  33.         while((output[opos]=='\n'||output[opos]==' '||output[opos]=='\t')&&opos!=0) opos--;
  34.         return !(apos^opos);
  35. }
  36. int digit(int num) {
  37.         if(num==0) return 0;
  38.         if(num<0) return digit(-num)+1;
  39.         int cnt=0;
  40.         while(num) num/=10,cnt++;
  41.         return cnt;
  42. }
  43. DWORD WINAPI func(LPVOID lpParamter) {
  44.         system("user<problem.in>problem.out");
  45. }
  46. int x=rand()%100,y=rand()%100;
  47. int main() {
  48.         srand(time(0));
  49.         fclose(fopen("problem.out","w"));
  50.         FILE* input=fopen("problem.in","w");
  51.         fprintf(input,"%d %d",x,y);
  52.         fclose(input);
  53.         HANDLE ut=CreateThread(0,0,func,0,0,0);
  54.         Sleep(1000);
  55.         FILE* out=fopen("problem.out","r");
  56.         fseek(out,0,2);
  57.         size_t size=ftell(out);
  58.         fseek(out,0,0);
  59.         char *output=(char*)malloc(size);
  60.         char *answer=(char*)malloc(digit(x)+digit(y)+2);
  61.         fread(output,1,size,out);
  62.         sprintf(answer,"%d",x+y);
  63.         if(size==0) printf("TLE");
  64.         else if(cmp(answer,output)) printf("AC");
  65.         else if(cmp2(answer,output)) printf("PE");
  66.         else printf("WA");
  67.         TerminateThread(ut,0);
  68. }
复制代码

选手程序:
  1. #include<stdio.h>
  2. int a,b;
  3. int main() {
  4.         scanf("%d%d",&a,&b);
  5.         printf("%d",a+b);
  6.         while(1);
  7. }
复制代码

我的程序在输出TLE后就无法关闭了,为什么?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-8-3 12:13:58 | 显示全部楼层
有人吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-5 09:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表