hdu1073 Online Judge 一道字符串处理的水题,,wa了我一下午。。。这几天发生了点不寻常的事。

Online Judge

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5735    Accepted Submission(s): 2157


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
 
要主要这样一组测试数据。
1
START
You are wrong!
END
START
You a
re wrong!
END
答案是AC。
我就忽略上面这种情况。
哎,代码写的非常屎。都不好意思贴出来了。
代码:
#include <stdio.h>
#include <string.h>

char ques[5010] , ans[5010] ,temp[5010];
int main()
{
	int t ;
	scanf("%d",&t) ;
	while(t--)
	{
		bool pe = false , wa = false ;
		gets(temp) ;
		while(strcmp(temp,"START")!=0)
		{
			gets(temp) ;
		}
		int len1 = 0 ;
		gets(temp) ;
		while(strcmp(temp,"END")!=0)
		{
			if(strlen(temp) == 0)
			{
				ques[len1++] = '\n' ;
			}
			else
			{
				strncpy(ques+len1,temp,strlen(temp)) ;
				len1 += strlen(temp) ;
				ques[len1++] = '\n' ;
			}
			gets(temp) ;
		}
		ques[len1] = '\0' ;
		gets(temp) ;
		while(strcmp(temp,"START")!=0)
		{
			gets(temp) ;
		}
		int len2 = 0 ;
		gets(temp) ;
		while(strcmp(temp,"END")!=0)
		{
			if(strlen(temp) == 0)
			{
				ans[len2++] = '\n' ;
			}
			else
			{
				strncpy(ans+len2,temp,strlen(temp)) ;
				len2 += strlen(temp) ;
				ans[len2++] = '\n' ;
			}
			gets(temp) ;
		}
		ans[len2] = '\0' ;
		if(strcmp(ques,ans) == 0)
		{
			puts("Accepted") ;
		}
		else
		{
			int i = 0 , j = 0 ;
			while(i<len1 && j<len2)
			{
				if(ques[i]!=ans[j])
				{
					if(ques[i] == ' ' || ques[i] == '\t' || ques[i] == '\n')
					{
						while(ques[i] == ' ' || ques[i] == '\t' || ques[i] == '\n')
						{
							++i ;
						}
						pe = true ;
					}
					if(ans[j] == ' ' || ans[j] == '\t' || ans[j] == '\n')
					{
						while(ans[j] == ' ' || ans[j] == '\t' || ans[j] == '\n')
						{
							
							++j ;
						}
						pe = true ;
					}
					if(ques[i]!=ans[j])
					{
						wa = true ;
						break ;
					}
				}
				++i,++j ;
			}
			if(i<len1)
			{
				while(ques[i] == ' ' || ques[i] == '\t' || ques[i] == '\n')
				{
					i++ ;
				}
				if(i<len1)
				{
					wa = true ;
				}
				else
				{
					pe = true ;
				}
			}
			if(j<len2)
			{
				while(ans[j] == ' ' || ans[j] == '\t' || ans[j] == '\n')
				{
					j++ ;
				}
				if(j<len2)
				{
					wa = true ;
				}
				else
				{
					pe = true ;
				}
			}
			if(wa)
			{
				puts("Wrong Answer") ;
			}
			else if(pe)
			{
				puts("Presentation Error") ;
			}
			else
			{
				puts("Accepted") ;
			}
		}
	}
	return 0 ;
}

与君共勉

就在前天,得知我喜欢的女生在一个星期前被其他的男生追到手了。
可笑的是,
我却还能非常淡定的面不改色的在这A题。
或许知道自己根本配不上吧。也不想耽误她。
人性总是自私的,感觉可以希望别人过的更好,却又见不得别人过得别自己好。Bye
祝你幸福。
如果这是一件错误的事情。
也都全怪我吧。
如果用梦想搪塞一切,也只是对自己的一种敷衍吧。
希望你开心。
这是你的新的开始,也是我的新的开始。

你可能感兴趣的:(字符串,online,judge,hdu1073)