NOJ——聊天止于呵呵(string流重定向+map,水题)
[1645] 聊天止于呵呵
- 时间限制: 5000 ms 内存限制: 65535 K
- 问题描述
(现代版)俗话说:流言止于智者,聊天止于呵呵。输入一段聊天记录,你的任务是数一数有
多少段对话“止于呵呵”,即对话的最后一句话包含单词 hehe 或者它的变形。
具体来说,我们首先提取出对话的最后一句话,把所有非字母的字符替换成空格,把所有字符 替换成小写,然后导出一个单词列表(由空格隔开),只要列表中的任何一个单词是 hehe,这 段对话就算作“止于呵呵”。比如,"Hi! Are you OK?" 会变成四个单词:hi, are, you, ok。注 意,单词列表可以是空的(比如,这句话是:"?!?!!")
有些人喜欢使用 hehe 的变形,这些变形也应被视为“呵呵”。为了简单起见,本题只考虑由 n(n>1)个 he 连接而成的单词,比如 hehehe 或者 hehehehe。注意,以 hehe 为连续子串的其他单 词不应视为“呵呵”,比如 hehee,或者 ehehe。
- 每两个不同人之间的所有对话算作“一段对话”。
- 输入
- 输入仅包含一组数据,每行是一句对话,格式为:
人名1->人名2: 一句话.
每行最多包含 1000 个字符,最多 100 行。 - 输出
- 输出“止于呵呵”的对话段落所占的百分比,四舍五入到最近的整数。输入数据保证答案不会
同时和两个整数最近。 - 样例输入
- A->B: Hello!
- A->C: Hi!
- B->A: Hehe
- B->D: Hei!
- D->B: How are you?
- A->C: Hi???
- A->C: Are you there?
- B->D: Hehehei!
- D->B: What does hehehei mean?
- F->E: I want to hehehehehe yah.
- A->B: Hello!
- 样例输出
- 50%
- 提示
- 样例解释
- A 和 B 之间的最后一句话是"Hehe".
- A 和 C 之间的最后一句话是"Are you there?".
- B 和 D 之间的最后一句话是"What does hehehei mean?".
- E 和 F 之间的最后一句话是"I want to hehehehehe yah". 最后第一段和最后一段话是“止于呵呵”的(注意最后一段对话是以呵呵的变种结束),因此 比例是 50%。
- 样例解释
map记录每一场对话,重定向来判断每句是否出现hehe。
代码:
- #include<iostream>
- #include<algorithm>
- #include<cstdlib>
- #include<sstream>
- #include<cstring>
- #include<cstdio>
- #include<string>
- #include<deque>
- #include<cmath>
- #include<queue>
- #include<set>
- #include<map>
- using namespace std;
- typedef long long LL;
- #define INF 0x3f3f3f3f
- inline int ishehe(string &s)
- {
- int len=s.size();
- if(len%2!=0||len<=2)
- return 0;
- for (int i=0; i<len; i++)
- {
- s[i]=tolower(s[i]);
- }
- for (int i=0; i<len; i+=2)
- {
- if(!(s[i]=='h'&&s[i+1]=='e'))
- return 0;
- }
- return 1;
- }
- inline string change(string &s)
- {
- string t,a,b;
- int len=s.size();
- for (int i=0; i<len; i++)
- {
- if(s[i]=='-'&&s[i+1]=='>')
- {
- s[i]=' ';
- s[i+1]=' ';
- }
- if(s[i]==':')
- s[i]=' ';
- }
- istringstream sin(s);
- sin>>a>>b;
- if(a<b)
- {
- t=t+a+b;
- }
- else
- {
- t=t+b+a;
- }
- return t;
- }
- int main(void)
- {
- string name,remark,sho,tname;
- int cnt=0;
- map<string,int>pos;
- map<string,int>::iterator it;
- while (getline(cin,name,' '))
- {
- getline(cin,remark);
- istringstream ssin(remark);
- tname=change(name);
- pos[tname]=0;
- while (ssin>>sho)
- {
- if(ishehe(sho))
- {
- pos[tname]=1;
- break;
- }
- }
- }
- for (it=pos.begin(); it!=pos.end(); it++)
- {
- if(it->second==1)
- {
- cnt++;
- }
- }
- printf("%.0lf%%\n",cnt*1.0*100/pos.size());
- return 0;
- }
NOJ——聊天止于呵呵(string流重定向+map,水题)的更多相关文章
- codeforces 637B B. Chat Order(map,水题)
题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- hdu 1004 颜色与数字(map水题)
Sample Input5 //Tgreenredblueredred 统计颜色的次数 输出最多的颜色3pinkorangepink0 Sample Outputred pink # include ...
- HDU 1029 某个数出现的次数大于等于(N+1)/2的是哪个 map水题
题意:输入n个数 n为奇数 问某个数出现的次数大于等于(N+1)/2的是 哪个 输出来Sample Input51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- Java I/O(二)其他常用的输入输出流PrintStream等、标准流重定向
四.FilterOutputStream.PrintStream PrintStream是继承自FilterStream类的,例如标准输出流System.out就是著名的PrintStream类对象. ...
- Java(45)JDK新特性之String流
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15201671.html 博客主页:https://www.cnblogs.com/testero ...
- Java_lambda表达式之"stream流学习,Map学习,collect学习,Conllectors工具类学习"
Lambda表达式学习 对List<Integer> userIdList = UserList.stream().map(User::getUserId).collect(Collect ...
- 实例学习SSIS(四)--使用日志记录和错误流重定向
原文:实例学习SSIS(四)--使用日志记录和错误流重定向 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习 ...
- hdu--1258--Sum It Up(Map水过)
Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- fork新建进程
#include <sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdio.h> ...
- Asp.Net Core 进阶(四)—— 过滤器 Filters
一.介绍 Asp.Net Core Filter 使得可以在请求处理管道的特定阶段的前后执行代码,我们可以创建自定义的 filter 用于处理横切关注点. 横切关注点的示例包括错误处理.缓存.配置.授 ...
- USACO08FEB Hotel
题目传送门 线段树维护区间 线段树结构体 struct zzz{ int l,r,mi; //l为以左端点的为起点的最长子串 //r为以右端点为终点的最长子串 //mi是区间内部的最长子串 }tree ...
- AddDbContext was called with configuration, but the context type 'NewsContext' only declares a parameterless constructor?
问题 An error occurred while starting the application. ArgumentException: AddDbContext was called with ...
- shell脚本,awk里面的BEGIN讲解。
解释: BEGIN{}这个特殊的pattern最常用的就是 变量赋值. BEGIN这个pattern就是文件没开始读的时候 执行 awk 'BEGIN{FS=":";OFS=&qu ...
- 01_1_jdom调用xml文件
01_1_jdom调用xml文件 1. 导入jdom.jar包 2. xml文件内容 test.xml <?xml version="1.0" encoding=" ...
- 01_3_查询指定id的单个对象
01_3_查询指定id的单个对象 1. 映射文件配置如下信息 <select id="selectStudentById" resultClass="Student ...
- tensorflow目标检测API之建立自己的数据集
1 收集数据 为了方便,我找了11张月儿的照片做数据集,如图1,当然这在实际应用过程中是远远不够的 2 labelImg软件的安装 使用labelImg软件(下载地址:https://github.c ...
- tensorflow目标检测API安装及测试
1.环境安装配置 1.1 安装tensorflow 安装tensorflow不再仔细说明,但是版本一定要是1.9 1.2 下载Tensorflow object detection API 下载地址 ...
- 设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml
eclipse提示警告如下: Build path specifies execution environment J2SE-1.5. There are no JREs installed in t ...