首页 技术 正文
技术 2022年11月19日
0 收藏 624 点赞 3,635 浏览 2591 个字

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 DescriptionIgnatius 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. InputThe 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. OutputFor each test cases, you should output the the result Judge System should return. Sample Input4
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 OutputPresentation 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(" \n\t")!=string::npos)
{
s.erase(s.find_first_of(" \n\t"),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++]="\n";
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++]="\n";
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]+'\n';
for (i=0; i<ui; i++)
cmpu=cmpu+user[i]+'\n';
era(cmpa);//去掉\n\t空格
era(cmpu);//去掉\n\t空格
if(cmpa!=cmpu)//去掉还不想等,肯定WA
{
cout<<"Wrong Answer"<<endl;
}
else//否则PE
{
cout<<"Presentation Error"<<endl;
}
}
}
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838