hdu 1073 Online Judge

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.
 

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
 


解题思路:其实就是简单地字符串匹配,但是以前搞了好久都没搞出来,今天周赛时刻,突然间有了灵感,终于A过,

   其中最主要的问题就是空行的统计。而且使用gets进行输入;思路:就是将ss1的所有字符统计在一个一位字符数组中,

   ss2的所有字符统计到另一个字符数组中,然后进行统一逐字匹配;成功,则A,否则,将所有的空格,空行,\t,全部剔除,

  之后在进行匹配,成功,则PE,否则 WR;


#include<stdio.h>
#include<string.h>
 int main()
  {
  	 char ss1[5150];
  	 char sss1[5050];
  	 char s1[20];
  	 char temp[5150];
  	 char ss2[5150];
  	 char sss2[5050];
  	 int T;
  	 int i,j;
  	 int len;
  	 int k;
	 scanf("%d",&T);
  	 while(T--)
  	  {
  	  	memset(ss1,0,sizeof(ss1));
  	  	memset(ss2,0,sizeof(ss2));
  	  	memset(sss1,0,sizeof(sss1));
  	  	memset(sss2,0,sizeof(sss2));
  	  	memset(temp,0,sizeof(temp));
  	  	 scanf("%s",s1);
  	  	<span style="color:#ff0000;"> while(gets(temp)&&strcmp(temp,"END")!=0)//主要在于此处,统计空行专用
  	  	   {
  	  	   	  if(strlen(temp)==0)    //对于gets()的第一个输入,有一个空行,要进行统计进去(两个),此处无关紧要,因为两者都加了一个,
				  strcat(ss1,"\n");//  而接下来的就是要真正要统计的空行;
				else
  	  	 	  	  strcat(ss1,temp);
  	  	   	  memset(temp,0,sizeof(temp));
  	  	   }
  	  	scanf("%s",s1);
  	  	     memset(temp,0,sizeof(temp));
  	  	 	 while(gets(temp)&&strcmp(temp,"END")!=0)
  	  	 	  {
				if(strlen(temp)==0)
				  strcat(ss2,"\n");
				else
  	  	 	  	  strcat(ss2,temp);	   
				  
			memset(temp,0,sizeof(temp)); 
  	  	 	  }
  	  	 </span>
  	  	if(strcmp(ss1,ss2)==0)
  	  	    k=1;
  	  	else
  	  	  {
  	  	  	  i=0;
  	  	  	  j=0;
  	  	  	  while(ss1[i]!='\0')
  	  	  	   {
  	  	  	   	 if(!(ss1[i]==' '||ss1[i]=='\t'||ss1[i]=='\n'))
						  sss1[j++]=ss1[i]; 
				i++;
  	  	  	   }
  	  	  	   i=0;
  	  	  	   j=0;
  	  	  	  while(ss2[i]!='\0')
  	  	  	   {
  	  	  	   	 if(!(ss2[i]==' '||ss2[i]=='\t'||ss2[i]=='\n'))
						  sss2[j++]=ss2[i]; 
					i++;
  	  	  	   }
  	  	  	  
			 if(strcmp(sss1,sss2)==0)
			    k=2;
			 else
			    k=3; 
  	  	  }
  	  	if(k==1)
  	  	   printf("Accepted\n");
  	  	else if(k==2)
  	  	   printf("Presentation Error\n");
  	  	else if(k==3)
  	  	   printf("Wrong Answer\n");
  	  	
  	  	 
  	  }
  	return 0;
  } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值