HDU——1073Online Judge(string类以及其对应函数)
Online Judge
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6534 Accepted Submission(s): 2472
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.
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.
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
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;
}
HDU——1073Online Judge(string类以及其对应函数)的更多相关文章
- 20140702 赋值构造函数的形参为什么一定用引用。string类的赋值运算函数的注意点
1.复制构造函数为什么一定要用引用,而不是用值 类名::复制构造函数(类名&引用名) 传递引用,可以避免复制,如果一个数据相当大的化,进行复制会浪费很多时间的. 类名::复制构造函数(类名 变 ...
- String类中的一些函数使用方法
最常用的就是Length()函数了,求字符串的长度 String s="";int i=s.length();i结果为0. 如果是String s=null;int i=s.len ...
- JAVA中String类的方法(函数)总结--JAVA基础
1.concat()方法,当参数为两字符串时,可实现字符串的连接: package cn.nxl123.www; public class Test { public static void main ...
- string类自定义字符串替换函数replace
#include <iostream> #include <string> using namespace std; /* * 函数功能:将string字符串中的某些字符替换 ...
- C++学习36 string类和字符串
C++大大增强了对字符串的支持,除了可以使用C风格的字符串,还可以使用内置的数据类型 string.string 类处理起字符串来会方便很多,完全可以代替C语言中的 char 数组或 char 指针. ...
- String类的比较
//strcmp只能运用于数组的比较 //string类可以用成员函数compare() //即a.compare(b) //例如 "; "; a.compare(b)返回值= & ...
- C++空类和string类
1. 空类 1.1 空类默认哪六个成员函数. class Empty { public: Empty(); //缺省构造函数 Empty e; Empty( const Empty& ); / ...
- string类------新标准c++程序设计
定义: string类是STL中basic_string模板实例化得到的模板类.其定义如下: typedef basic_string<char>string; 构造函数: string类 ...
- C++ STL介绍——String类
目录 1.简介 2.string类成员函数汇总 3.String类的构造函数以及析构函数 4.获取字符串长度 5.获取字符串元素 6.字符串比较方法 7.字符串输入输出 8.字符串查找函数 1.简介 ...
随机推荐
- HDU 4284 Travel (Folyd预处理+dfs暴搜)
题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...
- Python列表解析与生成器表达式
Python列表解析 l = ["egg%s" %i for i in range(100) if i > 50] print(l) l= [1,2,3,4] s = 'he ...
- QT+event() + 事件过滤器
其存在的意义: mywidget.h: #ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> namespace Ui { cl ...
- github:Commit failed - exit code 1 received
问题 使用github desktop 将项目提交到github,但提示Commit failed - exit code 1 received 开始以为名称过程,把名称改短,但还是失败. 原因 因为 ...
- 在线聊天项目1.4版 使用Gson方法解析Json字符串以便重构request和response的各种请求和响应 解决聊天不畅问题 Gson包下载地址
在线聊天项目结构图: 多用户登陆效果图: 多用户聊天效果图: 数据库效果图: 重新构建了Server类,使用了Gson方法,通过解析Json字符串,增加Info类,简化判断过程. Server类代码如 ...
- 关于flyme5显示不到和卸载不到旧应用解决方法
笔者买入一台mx5,升级flyme5后旧应用没有显示出来,而且在设置的应用管理都没显示旧应用. 通过adb命令: adb shell pm list packages显示所有包名, 查看自己要删除应用 ...
- pandas学习series和dataframe基础
PANDAS 的使用 一.什么是pandas? 1.python Data Analysis Library 或pandas 是基于numpy的一种工具,该工具是为了解决数据分析人物而创建的. 2.p ...
- PHP RBAC权限控制,基于CI框架(版本3.1.9)
2018年11月7日更新:目前功能已做到事件级别权限控制,如:后台用户的添加操作.删除操作和保存操作等具体到事件级的操作方法有权限则展示相应的操作菜单,没权限则隐藏相应菜单或提示无权限到目前算是真正做 ...
- Golang Json测试
结构体是谷歌搜索API package main import ( "encoding/json" "fmt" "io/ioutil" &q ...
- Ubuntu 18.04安装显卡驱动
安装完双系统,我遇到好几次开机或关机有问题,导致我重装了3次系统,第三次我才知道是显卡驱动问题,Ubuntu预装的开源Nvidia驱动太烂了,需要换官方驱动. 把 nouveau 驱动加入黑名单 $s ...