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.简介 ...
随机推荐
- TFS2018 找不到JRE 错误
配置TFS 2018 server configurion 报错 : Search requires Oracle Server JRE 7 Update 55 or higher or JRE 8 ...
- equals和HashCode的羁绊
equals和hashcode我一直没弄明白到底怎么回事,今天终于弄懂了. 如下图: 在Person类没有重写equals和hashcode方法时,是如下情况: 但是当我重写了equals方法时,是如 ...
- Spring框架配置文件中有两个相同名字的bean,最后会覆盖掉一个bean
问题容易出现在多个人合作的项目中,定义bean的名字的时候发生重复. 可以配置当bean定义重复的时候抛出异常,结束程序,强制提示更改重复的bean.
- MyBatis逆向工程中的Mapper接口以及Example的实例函数及详解
一.mapper接口中的方法解析 mapper接口中的函数及方法 方法 功能说明 int countByExample(UserExample example) thorws SQLException ...
- input类型
由于我们学习一个新的知识,而以前的都差不多忘完了,下面来复习我们以前学习的input的类型: button 点击的按钮 date 年/月/日 CheckBo ...
- COMP9021——6.3
有关yield的用法简介以及图灵机 第一节课大体没有太大变化,前半节课为了给图灵机的讲解做铺垫引入了yield.数组.字符串和文件等都是一个可迭代的对象,但由于它们的所有数据都存储与内存中,对内存的消 ...
- STM32的IAP方案
from: http://bbs.eeworld.com.cn/thread-294115-1-1.html 几乎所有的同类书籍都介绍综合性的应用示例如“万年历 + 温度显示 + 闹钟响铃 + 计 ...
- 数据结构和算法(What Why How)
数据结构和算法是什么? 从广义上讲,数据结构就是指一组数据的存储结构.算法就是操作数据的一组方法. 从狭义上讲,是指某些著名的数据结构和算法,比如队列.堆.栈.二分查找.动态规划等. 数据结构和算法有 ...
- hdu2604 递推转换矩阵快速幂
刚开始还以为用位运算与或几下几个循环就搞定了,算着算着发现不行........ 还是一种固定的切题角度,我假设有长度为n,总的排列数位f(n),怎么算他呢?从后往前考虑,因为大多数情况,都是用前面的结 ...
- HDU 5528 Count a * b 欧拉函数
题意: 定义函数\(f(n)\)为\(i \cdot j \not\equiv 0 \; (mod \; n)\)的数对\((i,j)\)的个数\((0 \leq i,j \leq n)\) \(g( ...