注解
1、模拟题,模拟输入过程,字符串处理。
2、用两个数组分别保存实际输出和正确输出,首先比较两个字符串是否相同,若不相同,分别将两个数组的空格、Tab键、回车等都去掉,再去比较两个字符串是否相同。若还是不同,则输出WA;如果去掉后相同,输出PE;如果一开始就相同,输出AC。
3、详细了解ACM赛制中的几种输出形式:AC,PE,RE,WA等。
代码
#include <iostream>
#include <sstream>
using namespace std;
int stringToInt(string s) {
stringstream ss;
ss<<s;
int n;
ss>>n;
return n;
}
string str[2];
string tmp[2];
string replaceStr[2];
void input() {
for(int j=0; j<2; j++) {
tmp[j] = "";
str[j] = "";
getline(cin, tmp[j]);
while(tmp[j].compare("END")) {
if(tmp[j].compare("START")) {
str[j] += tmp[j] + "\n";
}
getline(cin, tmp[j]);
}
}
for(int j=0; j<2; j++) {
replaceStr[j] = "";
for(int k=0; k<str[j].length(); k++) {
if(str[j].at(k)!=' ' && str[j].at(k)!='\t' && str[j].at(k)!='\n') {
replaceStr[j] += str[j].at(k);
}
}
}
}
int main() {
string s;
getline(cin, s);
int N = stringToInt(s);
for(int i=0; i<N; i++) {
input();
if(str[0].compare(str[1])) {
if(replaceStr[0].compare(replaceStr[1])) {
cout<<"Wrong Answer"<<endl;
} else {
cout<<"Presentation Error"<<endl;
}
} else {
cout<<"Accepted"<<endl;
}
}
return 0;
}