Online Judge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6534 Accepted Submission(s): 2472
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.
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.
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
对于熟悉string类及其函数、getline、erase、何时用getchar()读掉换行符等等有些帮助
思路:首先明确AC、WA、PE的文本到底差在什么地方..建两个string数组,分别储存多行ac代码和user代码,重点就在储存这里。既然用了getline那么换行符是会被读进去,但是又会被自动替换成空气(空格、制表符可以倒是完全正常读取并储存),因此结果是什么都没有,但只是结果,读取还是可以的,所以一旦读取之后变成了什么都没有,那么这肯定是个换行符,那你手动补上一个换行符即可。其次就是注意getchar什么时候用,F9单步调试调试相信会知道的
代码:
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<sstream> using namespace std; void era(string &s)//WA和PE的就用这个擦除空格回车制表符的函数来决定了 { while (s.find_first_of(" ")!=string::npos) { s.erase(s.find_first_of(" "),1); } } int main(void) { int t,i,j,ai,ui; bool ok; cin>>t; getchar(); while (t--) { string ac[1000],user[1000],ts,cmpa,cmpu; ai=0;//ac行数初始化 while (getline(cin,ts))//用临时变量可解决开始结尾甚至换行符问题 { if(ts=="START") continue; else if(ts=="END") break; else if(ts=="") user[ui++]=" "; else ac[ai++]=ts; } ui=0;//user行数初始化 while (getline(cin,ts)) { if(ts=="START") continue; else if(ts=="END") break; else if(ts=="") user[ui++]=" "; else user[ui++]=ts; } ok=1;//假设AC for (j=0; j<max(ai,ui); j++) { if(user[j]!=ac[j]) { ok=0; break; } } if(ok) { cout<<"Accepted"<<endl; } else { for (i=0; i<ai; i++) cmpa=cmpa+ac[i]+' '; for (i=0; i<ui; i++) cmpu=cmpu+user[i]+' '; era(cmpa);//去掉 空格 era(cmpu);//去掉 空格 if(cmpa!=cmpu)//去掉还不想等,肯定WA { cout<<"Wrong Answer"<<endl; } else//否则PE { cout<<"Presentation Error"<<endl; } } } return 0; }