2020 BIT冬训-模拟与暴力 A - Online Judge HDU - 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('\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.

InputThe 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.
OutputFor 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

这题主要是创建多个字符串。还需要创建两个去掉' '、'\n\'、'\t'的字符串来判断是否PE。
以及需要注意scanf会留下一个'\n'。需要处理一下不然会被gets吃掉。
#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
int n,t;
char user[5005],ans[5005],temp[5005],pe1[5005],pe2[5005]; 
int main(){
    scanf("%d",&n);
    while(n--){
        user[0]='\0';
        ans[0]='\0';
        gets(temp);
        while(strcmp(temp,"START")!=0)
            gets(temp);
        while(gets(temp)){
            if(strcmp(temp,"END")==0)
                break;
            if(strlen(temp)!=0)
                strcat(ans,temp);
            strcat(ans,"\n");
        }
        gets(temp);
        while(gets(temp)){
            if(strcmp(temp,"END")==0)
                break;
            if(strlen(temp)!=0)
                strcat(user,temp);
            strcat(user,"\n");
        }
        if(strcmp(ans,user)==0)
            printf("Accepted\n");
        else{
            t=0;
            for(int i=0;i<strlen(user);i++)
                if(user[i]!=' '&&user[i]!='\t'&&user[i]!='\n')
                    pe1[t++]=user[i];
            pe1[t]='\0';
            t=0;    
            for(int i=0;i<strlen(ans);i++)
                if(ans[i]!=' '&&ans[i]!='\t'&&ans[i]!='\n')
                    pe2[t++]=ans[i];
            pe2[t]='\0';
            if(strcmp(pe1,pe2)==0)
                printf("Presentation Error\n");
            else
                printf("Wrong Answer\n");
        }
    }
}

 

上一篇:3C - Tic-tac-toe


下一篇:Matlab:数模09-线性规划模型