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.简介 ...
随机推荐
- 2018.5.4 AndroidStudio遇到的问题
新建项目初出现异常报错 Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict 发生这类型的错误, ...
- falling object思路总结
1.用检测的方法把falling object标记为一个类别,然后检测出类别.这种方式不可行的原因:因为falling object可能是任何东西,所以可能是一个路锥,也可能是一个玻璃瓶,还可能是掉下 ...
- VC-基础:vs2010快捷键
F12: 转到所调用过程或变量的定义 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O 打开文件 CTRL + SHIFT + O打开项目 CTRL + S ...
- CPP-STL:vector的内存释放
1. vector容器的内存自增长 与其他容器不同,其内存空间只会增长,不会减小.先来看看"C++ Primer"中怎么说:为了支持快速的随机访问,vector容器的元素以连续方式 ...
- mini_httpd的安装和配置
1.下载:http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz 2.解压:tar zxvf mini_httpd-1.19.ta ...
- 简单的邮件发送mail.jar
public class MailSender { final static Logger logger = Logger.getLogger(MailSender.class); /** * 发送简 ...
- Spring中使用事务搭建转账环境 转账操作,
演示不使用事务出现异常情况 Dao层两个方法lessMoney()和moreMoney() package com.swift; import org.springframework.jdbc.cor ...
- 使用CAShapeLayer实现复杂的View的遮罩效果
一.案例演示 最近在整理一个聊天的项目的时候,发送图片的时候,会有一个三角的指向效果,指向这张图片的发送者.服务端返回给我们的图片只是一张矩形的图片,我们如何把一张矩形的图片或者View,加上一层自定 ...
- NOIP计划索引
药丸的节奏 亟待解决的问题 灵光一现的trick 2018上学期刷题记录 NOIP2018 - 暑期博客整理 NOIP2018 - 一些板子 NOIP2018 - 每日填坑
- sphinx关键字套红
sphinx定义搜索结果,搜索的内容着重显示,可以使用下面代码 <?php /** * Created by PhpStorm. * User: pc00001 * Date: 2015/4/1 ...