HDOJ1073(Online Judge)(模拟+容器的使用)

来源:互联网 发布:aix java 环境变量 编辑:程序博客网 时间:2024/05/01 00:20

Online Judge

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


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
4START1 + 2 = 3ENDSTART1+2=3ENDSTART1 + 2 = 3ENDSTART1 + 2 = 3ENDSTART1 + 2 = 3ENDSTART1 + 2 = 4ENDSTART1 + 2 = 3ENDSTART1+2=3END
 

Sample Output
Presentation ErrorPresentation ErrorWrong Answer

Presentation Error

getline()函数用于输入流,读取字符到buffer中,直到下列情况发生:

  • num - 1个字符已经读入,
  • 碰到一个换行标志,
  • 碰到一个EOF,
  • 或者,任意地读入,直到读到字符delimdelim字符不会被放入buffer中。
用容器进行操作简单了许多也比较好理解。

#include<iostream>#include<string>#include<vector>using namespace std;vector<string> v1,v2;int main(){string s,str1,str2;int test;cin>>test;while(test--){while(getline(cin,s)){if(s=="START") continue;if(s=="END") break;v1.push_back(s);for(int i=0;i<s.length();i++){if(s[i]!=' '&&s[i]!='\t')    str1+=s[i];}}while(getline(cin,s)){if(s=="START") continue;    if(s=="END"){if(v1==v2)    printf("Accepted\n");else if(str1==str2)    printf("Presentation Error\n");else    printf("Wrong Answer\n");break;}v2.push_back(s);for(int i=0;i<s.length();i++){if(s[i]!=' '&&s[i]!='\t')    str2+=s[i];}}v1.clear(),v2.clear();str1.resize(0),str2.resize(0); }}

0 0
原创粉丝点击