HDU 1073 Online Judge (字符串处理)
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 (字符串处理)的更多相关文章
- HDOJ/HDU 1073 Online Judge(字符串处理~)
Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...
- HDU 1073 Online Judge(字符串)
Online Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- 解题报告:hdu 1073 Online Judge
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 Problem Description Ignatius is building an Onli ...
- HDU 1073 - Online Judge
模拟评测机判断答案 先判断有没有不一样的 有的话再提取出 有效子列 看看有没有错的 #include <iostream> #include <cstdio> #include ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- hdu 1073 字符串处理
题意:给一系列的输出和标准答案,比较二者是AC,PE或WA 字符串处理还是比较薄弱,目前没什么时间搞字符串专题,所以遇到一题就努力搞懂 #include<cstdio> #include& ...
- HDU 1073
http://acm.hdu.edu.cn/showproblem.php?pid=1073 模拟oj判题 随便搞,开始字符串读入的细节地方没处理好,wa了好久 #include <iostre ...
- HDU2112 HDU Today 最短路+字符串哈希
HDU Today Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1062 Text Reverse 字符串
Text Reverse Time L ...
随机推荐
- Linux内核0.11 bootsect文件说明
一.总体功能介绍 这是关于Linux-kernel-0.11中boot文件夹下bootsect.s源文件的说明,其中涉及到了一些基础知识可以参考这两篇文章. 操作系统启动过程 软盘相关知识和通过BIO ...
- centos6.7 安装JDK
1.卸载JDK 查看系统是否已安装JDK.一般的linux都默认使用了开源的openJDK.显示JDK版本信息,已经安装JDK,否则没有安装.命令行: [root@localhost ~]# ja ...
- UVA10917_Walk Through the Forest
无向图.对于两个相连的点,如果A到终点的最短路径大于B到终点的最短路径,那么A可以往B走,求最终从起点到终点有多少种走法? 首先我们可以直接预处理所有点到终点的最短路径.然后分别判断所有的边两点是否满 ...
- ZooKeeper-基础介绍
What is ZooKeeper? ZooKeeper为分布式应用设计的高性能(使用在大的分布式系统).高可用(防止单点失败).严格地有序访问(客户端可以实现复杂的同步原语)的协同服务. ZooKe ...
- [洛谷P4340][SHOI2016]随机序列
题目大意:有$n(n\leqslant10^5)$个数,每两个数之间可以加入$+-\times$三种符号,$q(q\leqslant10^5)$次询问,每次询问修改一个数后,所有表达式可能的值的和 题 ...
- java中poi进行execl导出
首先贴出最终导出的execl截图吧: 前台界面如下: 点击导出时,为其按钮的onclick事件添加exportDate()函数: function exportDate(){ var begin_Da ...
- BZOJ4416 [Shoi2013]阶乘字符串 【序列自动机 + 状压dp】
题目链接 BZOJ4416 题解 建立序列自动机,即预处理数组\(nxt[i][j]\)表示\(i\)位置之后下一个\(j\)出现的位置 设\(f[i]\)表示合法字符集合为\(i\)的最短前缀,枚举 ...
- SpringBoot的基础
概念 Spring的优缺点 1. 优点(AOP和IOC简化开发) Spring是Java企业版(Java Enterprise Edition,JEE,也称J2EE)的轻量级代替品.无需开发重量级的E ...
- loj6070【山东集训第一轮Day4】基因
题解: 分块对每个块的起点$st[i]$到$n$做一次回文自动机; 由于子串的回文自动机是原串的子图,所以并不需要重新构图,在原来的图上做即可: 做的时候记录某个终点的本质不同的回文串和$sum[i] ...
- 字典的setdefault() 和get()方法比较
Python 字典 setdefault() 函数 和get() 类似: 如果键存在字典中,返回其value值 如果键不存在字典中,创建键值对.完后,返回值为默认值. 话不多说,上栗子: setdef ...