思路:
模拟,把实现功能分块写。
一是比较结果、二是得到删除\n\t等字符后的字符串
比较两个结果
通过
- 直接比较
- 删除\n \t等字符后比较
#include<iostream>
using namespace std;
int n;
void delete_all(string &a){ //删除所有的格式
string b = "";
for(int i = 0;i < a.length();i++){
if(a[i]!=' '&&a[i]!='\t'&&a[i]!='\n'){
b+=a[i];
}
}
a = b;
}
int compare_ab(string a,string b){ // 比较俩个字符串
if(a == b) return 1;
delete_all(a);
delete_all(b);
if(a == b) return 2;
return 0;
}
void read(){
cin>>n;
string user_str = "";
string judge_str = "";
for(int i = 0;i<n;i++){
user_str = "";
judge_str = "";
string str="";
while(str!="END"){
getline(cin,str);
if(str!="START"&&str!="END"){
user_str += str;
if(str=="") user_str+='\n'; // 拼接时要注意有换行
}
}
str="";
while(str!="END"){
getline(cin,str);
if(str!="START"&&str!="END"){
judge_str += str;
if(str=="") user_str+='\n';
}
}
int result = compare_ab(judge_str,user_str);
if(result == 0) printf("Wrong Answer\n");
else if(result == 1) printf("Accepted\n");
else printf("Presentation Error\n");
// cout<<user[i]<<endl;
}
}
int main()
{
read();
// judge();
return 0;
}