C - Online Judge
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('\t'), or enters('\n'), 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 10000
int F(char ch)// 判断是否为 空格 换行符 水平制表符
{
if(ch == ' ' || ch == '\n' || ch == '\t')
return 1;
else
return 0;
}
int injuge(char * ans, char * test)// 判断 函数, 1 : Accepted 2 : Presentation Error 3 : Wrong Answer
{
if(strcmp(ans, test) == 0) return 1;
char s1[N] = {0}, s2[N] = {0};
int i, k;
for(i = 0, k = 0; ans[i] != '\0'; i++)
if(!F(ans[i]))
s1[k++] = ans[i];
for(i = 0, k = 0; test[i] != '\0'; i++)
if(!F(test[i]))
s2[k++] = test[i];
if(strcmp(s1, s2) == 0)
return 2;
else
return 3;
}
void input(char * str)// 输入函数
{
while(1)
{
char temp[N] = {0};
gets(temp);
if(strcmp(temp, "START") == 0) continue;
if(strcmp(temp, "END") == 0) break;
if(temp[0] == 0)
strcat(str, "\n");// 如果不判断为空的情况加上一个换行符的话,有可能会把presentation 变成 Accept(错误点)
else
strcat(str, temp);
}
}
int main()
{
int t;
scanf("%d", &t);
getchar();
while(t--)
{
char ans[N];// correct answer
char test[N];// input answer
memset(ans, 0, sizeof(ans));// 对字符串数组进行初始化(新学的)
memset(test, 0, sizeof(test));
input(ans);
input(test);
int num = injuge(ans, test);
if(num == 1)
printf("Accepted\n");
else if(num == 2)
printf("Presentation Error\n");
else
printf("Wrong Answer\n");
}
return 0;
}