1073(OnlineJudge)

Online Judge

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2773 Accepted Submission(s): 1008


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.

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.

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
 
关键 在于换行的读入 采用了c++中的 getline 函数

原型

  istream& getline ( istream& , streamsize& , char delim );
  istream& getline ( istream& , streamsize& );

参数

  is 进行读入操作的输入流
  str 存储读入的内容
  delim 终结符

返回值

  与参数is是一样的

功能

  将输入流is中读到的字符存入str中,直到遇到终结符delim才结束。对于第一个函数delim是可以由用户自己定义的终结符;对于第二个函数delim默认为 '\n'(换行符)。
  函数在输入流is中遇到文件结束符(EOF)或者在读入字符的过程中遇到错误都会结束。
  在遇到终结符delim后,delim会被丢弃,不存入str中。在下次读入操作时,将在delim的下个字符开始读入。
  举例:
  int main()
  {
  string str;
  getline(cin,str,'#');
  char c=getchar();
  cout<<str<<' '<<c<<endl;
  return 0;
  }
  输入为:aa#b
  输出为:aa b

注意

  这个getline是个全局函数,而不是istream的成员函数getline。
 
 
 
代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int t,i;
  string s1,s2;
  string data,input;
  scanf("%d",&t);
  getchar();                      //过滤掉数字后的回车字符,防止后面多读一行
  while(t--)
  {
    data = input = "";
    while(getline(cin,s1) && s1!="END")
    {
      if (s1=="")              //处理空行,下同
      {
                              data+='\n';
                              continue;
                      }
      s1+='\n';  //每行结束的换行符还是要记录
      data+=s1;
    }
    while(getline(cin,s2) && s2!="END")
    {
      if (s2=="")
      {
                              data+='\n';
                              continue;
                      }
      s2+='\n'; // //每行结束的换行符还是要记录

      input+=s2;
    }
    if(data==input)
    {
      printf("Accepted\n");continue;
    }
    s1=s2="";
    for(i=6;i<data.length();i++)
      if(data[i]!='\t'&&data[i]!='\n'&&data[i]!=' ')
        s1+=data[i];
    for(i=6;i<input.length();i++)
      if(input[i]!='\t'&&input[i]!='\n'&&input[i]!=' ')
        s2+=input[i];
    if(s1!=s2)printf("Wrong Answer\n");
    else printf("Presentation Error\n");
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值