解题报告:hdu 1073 Online Judge

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073

Problem Description

Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user's result file, then the system compare the two files. If the two files are absolutly same, then the Judge System return "Accepted", else if the only differences between the two files are spaces(' '), tabs(' '), or enters(' '), the Judge System should return "Presentation Error", else the system will return "Wrong Answer".
Given the data of correct output file and the data of user's result file, your task is to determine which result the Judge System will return.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case has two parts, the data of correct output file and the data of the user's result file. Both of them are starts with a single line contains a string "START" and end with a single line contains a string "END", these two strings are not the data. In other words, the data is between the two strings. The data will at most 5000 characters.

Output

For each test cases, you should output the the result Judge System should return.

Sample Input

4
START
1 + 2 = 3
END
START
1+2=3
END
START
1 + 2 = 3
END
START
1 + 2 = 3
 
END
START
1 + 2 = 3
END
START
1 + 2 = 4
END
START
1 + 2 = 3
END
START
1    +    2    =    3
END

Sample Output

Presentation Error
Presentation Error
Wrong Answer
Presentation Error

伊格内修斯正在建立一个在线法官,现在他已经研究出除法官系统以外的所有问题。系统必须从正确的输出文件和用户的结果文件读取数据,然后系统比较这两个文件。如果两个文件绝对相同,则判定系统返回“Accepted”,否则如果两个文件之间的唯一区别是空格('  '),制表符(' ')或输入(' '),法官系统应返回“Presentation Error”,否则系统将返回“Wrong Answer”。

给定正确输出文件的数据和用户结果文件的数据,您的任务是确定判定系统将返回哪个结果。  

输入

输入包含多个测试用例。输入的第一行是单个整数T,它是测试用例的数量。 T测试用例如下。 每个测试用例都有两个部分,正确输出文件的数据和用户结果文件的数据。它们都是以单行开始,包含一个字符串“START”,并以单行结尾包含一个字符串“END”,这两个字符串不是数据。换句话说,数据在两个字符串之间。数据最多为5000个字符。  

输出

对于每个测试用例,您应输出Judge System应返回的结果。

解题思路:

做这道题时,因为我们只知道数据是在START与END之间给出的,而且从输入输出实例来看,我们需要循环读入START与END之间的每行字符串,保存在一个字符数组中,再循环读入非空格,制表符,换行符的字符到另一个字符数组中,这样来比较,思路就很清楚了,注解在代码中。。。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=5005;
 4 char tmp[N];//用来读取暂时的字符串
 5 char a1[N],a2[N],b1[N],b2[N];
 6 void input(char *a,char *b)
 7 {
 8     gets(tmp);//首先读入START
 9     while(strcmp(tmp,"START")!=0)gets(tmp);//当输入的不是START(有可能是空行)时,继续输入,否则就不执行此句
10     while(gets(tmp)){//接下来循环读入START与END之间的每行字符串
11         if(strcmp(tmp,"END")==0)break;//结束条件,跳出
12         if(strlen(tmp)!=0)strcat(a,tmp);//当输入的不是空字符串的时候(忽略单行的空字符串),即可链接保存在a数组后面
13         strcat(a,"
");//多加一个换行符,下次链接的时候就可直接把'
'覆盖掉,保留实际的行读入操作,同时也作为标记
14     }
15     int k=0,n=strlen(a);
16     for(int i=0;i<n;++i)//循环赋值给b数组
17         if(a[i]!=' ' && a[i]!='	' && a[i]!='
')b[k++]=a[i];//当a是空格,制表符,结束符则不保存在b数组里面
18     b[k]='';//要求匹配对应的格式
19 }
20 int main()
21 {
22     int t;
23     cin>>t;
24     while(t--){
25         a1[0]=a2[0]=b1[0]=b2[0]='';//记得数组初始化
26         input(a1,b1);//两部分输入
27         input(a2,b2);
28         if(strcmp(a1,a2)==0)cout<<"Accepted"<<endl;//当a1==a2时表明文本输入相同
29         else if(strcmp(b1,b2)==0)cout<<"Presentation Error"<<endl;//否则修改后表明格式不匹配
30         else cout<<"Wrong Answer"<<endl;//否则就是错误答案
31     }
32     return 0;
33 }
原文地址:https://www.cnblogs.com/acgoto/p/8637706.html