题目回顾(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.
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
6
8
Sample Output
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
源码与解析
字符串水题,不过温故一下输入带空格换行的字符串。
#include<iostream>
#include<string>
using namespace std;
string start;
string s;
string s1,s2;
int compare(){
if(s1==s2){
return 1;
}
string ss1="";
string ss2="";
for(int i=0;i<s1.length();i++){
if(s1[i]!=' '&&s1[i]!='\n'&&s1[i]!='\t'){
ss1+=s1[i];
}
}
for(int i=0;i<s2.length();i++){
if(s2[i]!=' '&&s2[i]!='\n'&&s2[i]!='\t'){
ss2+=s2[i];
}
}
if(ss1==ss2){
return 2;
}else{
return 3;
}
}
int main(){
int n;
cin>>n;
while(n--){
s1="";
s2="";
cin>>start;
while(getline(cin,s)){
if(s!="END"){
s1+=s;
s1+='\n';
}else{
break;
}
}
cin>>start;
while(getline(cin,s)){
if(s!="END"){
s2+=s;
s2+='\n';
}else{
break;
}
}
switch(compare()){
case 1:
cout<<"Accepted"<<endl;
break;
case 2:
cout<<"Presentation Error"<<endl;
break;
case 3:
cout<<"Wrong Answer"<<endl;
break;
}
}
return 0;
}