题目链接

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

分析:

首先是对于数据的输入部分,只能够用gets()来一行一行的读入,不能用scanf(),也不能一个字符一个字符的读入(scanf()是因为遇到空格就自动结束了,最后字符串中间的空格都没有读进去;如果一个字符一个字符的读的话,可能中间会出现"END"子串,让输入在不该结束的地方提前结束了),这样才能保证读到完全正确的data数据部分。

最主要的是运用一些字符串处理的函数,就很容易了。

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
char a[5009],b[5009];
void trim(char *s)//对字符串进行处理,去掉里面的空格、换行和tabs
{
char temp[5009];
int j=0;
for(int i=0; i<strlen(s); i++)
{
if(s[i]!=' '&&s[i]!='\t'&&s[i]!='\n')
{
temp[j]=s[i];
j++;
}
}
temp[j]='\0';
strcpy(s,temp);
}
void Compare(char *a,char *b)
{
if (strcmp(a,b)==0)
{
printf("Accepted\n");
return ;
}
trim(a);
trim(b);
if (strcmp(a,b)==0)//去掉空格、换行、tabs后相等
{
printf("Presentation Error\n");
return ;
}
else
{
printf("Wrong Answer\n");
return ;
}
}
void input(char * s)
{
char temp[5009];
gets(temp);
if(strcmp(temp,"START")==0)//从此处才开始得到data部分
{
gets(temp);//注意这里一定要用gets()来进行读入,因为scanf()不能读入空格
while(strcmp(temp,"END")!=0)
{
if(strlen(temp)==0)
strcat(s,"\n");//字符串追加
else
strcat(s,temp);
gets(temp);
}
}
}
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
strcpy(a,"\0");//对a字符串进行刷新
strcpy(b,"\0");//对b字符串进行刷新
input(a);
input(b);
Compare(a,b);
}
return 0;
}

HDU 1073 Online Judge (字符串处理)的更多相关文章

  1. HDOJ/HDU 1073 Online Judge(字符串处理~)

    Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...

  2. HDU 1073 Online Judge(字符串)

    Online Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  3. 解题报告:hdu 1073 Online Judge

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 Problem Description Ignatius is building an Onli ...

  4. HDU 1073 - Online Judge

    模拟评测机判断答案 先判断有没有不一样的 有的话再提取出 有效子列 看看有没有错的 #include <iostream> #include <cstdio> #include ...

  5. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  6. hdu 1073 字符串处理

    题意:给一系列的输出和标准答案,比较二者是AC,PE或WA 字符串处理还是比较薄弱,目前没什么时间搞字符串专题,所以遇到一题就努力搞懂 #include<cstdio> #include& ...

  7. HDU 1073

    http://acm.hdu.edu.cn/showproblem.php?pid=1073 模拟oj判题 随便搞,开始字符串读入的细节地方没处理好,wa了好久 #include <iostre ...

  8. HDU2112 HDU Today 最短路+字符串哈希

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. hdu 1062 Text Reverse 字符串

    Text Reverse                                                                                  Time L ...

随机推荐

  1. [转帖]UsingDiskspdforSQLServer --- 改天做下练习 官方文档.

    Using DiskSpd in SQL Server environments Writer: Robert Beene Contributors: Jose Barreto, Ramu Konid ...

  2. c++ 替换修改一个文件夹下的所有文件的文件名

    代码简洁,亲测可用. 1,首先来获取(输出)一个文件夹中所有的文件名 void getFiles(string path, vector<string>& files) { //文 ...

  3. crosses initialization of “XXX” 的问题

    在switch-case中定义了变量,用g++编译的时候报错crosses initialization of “XXX” ,在网上一查,说是gcc要求变量的定义不能位于goto之后 将变量定义放在s ...

  4. 一道面试题:StringBuffer a=new StringBuffer ("A"); StringBuffer b=new StringBuffer

    前几天又看到这个面试题,再次看看 public class Jtest{ public static void main(String[] args) { StringBuffer a=new Str ...

  5. 如何规范 CSS 的命名和书写

    我开始学前端的时候也是对于规范问题头疼,后来看了网易的NEC规范,惊呼牛逼 NEC : 更好的CSS样式解决方案 只遵循横向顺序即可,先显示定位布局类属性,后盒模型等自身属性,最后是文本类及修饰类属性 ...

  6. BZOJ5102 POI2018Prawnicy(堆)

    考虑固定右端点,使左端点最小.那么按右端点排序后查询前缀这些区间的左端点第k小即可.然而写了一个treap一个线段树都T飞了,感觉惨爆.事实上可以用堆求第k小,维护一个大根堆保证堆中元素不超过k个即可 ...

  7. python selenium wait方法

    遇到一个网站运行很慢,所以要等待某个元素显示出来之后再进行操作,自己手上的书上没有例子可以直接用 发现一篇文章:http://www.cnblogs.com/yoyoketang/p/6517477. ...

  8. 如何认识TOS----DSCP 对照表

    如何认识TOS----DSCP 对照表 最近有遇到项目中对FortiGate设置TOS的策略路由的问题,其实这问题较为简单,但是由于大家对TOS-DSCP概念不熟悉造成的,所以感觉比较难,现在不同厂商 ...

  9. bzoj : 4504: K个串 区间修改主席树

    4504: K个串 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 268  Solved: 110[Submit][Status][Discuss] ...

  10. chrome神插件之:SwitchyOmega的安装设置

    转至:http://yiweifen.com/v-1-118586.html 前言 往常找某草的网站基本上是这样的:先FQ,然后谷歌找1024,出现很多某草的更新地址,大多都是广告,大约需要花十几分钟 ...