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.简介 ...
随机推荐
- MovieReview—Kingsman THE SECRET SERVICE(王牌特工之特工学院)
Brain Storming Mr. Valentine's Day see excess human beings as the Earth's virus and try to e ...
- OpenGL小试牛刀第二季(粒子模拟)
效果截图:粒子模拟代码展示:#include "Particle.h" /** 构造函数 */CParticle::CParticle(){ data = NULL; numpar ...
- Android(java)学习笔记114:Service生命周期
1.Service的生命周期 Android中的Service(服务)与Activity不同,它是不能和用户交互,不能自己启动的,运行在后台的程序,如果我们退出应用的时候,Servic ...
- python基础一 day15 内置函数
'\r' 回车,回到当前行的行首,而不会换到下一行,如果接着输出的话,本行以前的内容会被逐一覆盖: '\n' 换行,换到当前位置的下一行,而不会回到行首: # print()# input()# le ...
- python实现单链表翻转
题目描述: 翻转一个链表 您在真实的面试中是否遇到过这个题? Yes 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null 挑 ...
- 从Docker到Kubernetes进阶
分享个网站,k8s技术圈阳明大佬的网站 现在基本都用有道云笔记了,比较方便,所以准备弃用博客园了...
- java用org.apache.poi包操作excel
一.POI简介 Jakarta POI 是apache的子项目,目标是处理ole2对象.它提供了一组操纵Windows文档的Java API 目前比较成熟的是HSSF接口,处理MS Excel(97- ...
- android 通过adb 和 ndk调试堆栈
打开终端 , 输入以下命令, armeabi是应用编译好的.so库的路径 adb logcat|ndk-stack -sym ./armeabi/ 如果堆栈报错,会弹出报错内容. 如下: C:\Use ...
- 【转】Windows 邮件槽(MailSlot)
Windows 邮件槽(MailSlot) 来自<Windows网络编程第二版 中文版> 优点:通过网络,将一条消息广播给一台或多台计算机. 缺点:只允许从客户机到服务器,建立一种不可 ...
- C#_接口基础学习
参考:https://www.cnblogs.com/hamburger/p/4681681.html