• [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.
  • 样例输出
  • 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,水题)的更多相关文章

  1. codeforces 637B B. Chat Order(map,水题)

    题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. hdu 1004 颜色与数字(map水题)

    Sample Input5 //Tgreenredblueredred 统计颜色的次数 输出最多的颜色3pinkorangepink0 Sample Outputred pink # include ...

  3. 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 ...

  4. HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)

    Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...

  5. Java I/O(二)其他常用的输入输出流PrintStream等、标准流重定向

    四.FilterOutputStream.PrintStream PrintStream是继承自FilterStream类的,例如标准输出流System.out就是著名的PrintStream类对象. ...

  6. Java(45)JDK新特性之String流

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15201671.html 博客主页:https://www.cnblogs.com/testero ...

  7. Java_lambda表达式之"stream流学习,Map学习,collect学习,Conllectors工具类学习"

    Lambda表达式学习 对List<Integer> userIdList = UserList.stream().map(User::getUserId).collect(Collect ...

  8. 实例学习SSIS(四)--使用日志记录和错误流重定向

    原文:实例学习SSIS(四)--使用日志记录和错误流重定向 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习 ...

  9. 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 ...

随机推荐

  1. Python-OpenCV——Image Blurring(Image Smoothing)

    通过将图像与低通滤波器内核卷积来实现图像模糊.它有助于消除噪音.它实际上从图像中去除了高频内容(例如:噪声,边缘).因此在此操作中边缘会有点模(嗯,有模糊技术,也不会模糊边缘). OpenCV主要提供 ...

  2. 实验十三 团队作业9:Beta冲刺与团队项目验收

    实验十三 团队作业9:Beta冲刺与团队项目验收 实验时间 2019-6-20(21) Deadline: [6.20-6.26]之间任选连续3天的23:00,以团队随笔博文提交时间为准. 评分标准: ...

  3. 在2d游戏中常用的向量方式

    function cc.exports.VectorRotateByAngle(vector,angle)--计算向量旋转后的向量,angle:正数逆时针,负输顺时针 angle = angle*ma ...

  4. 学习笔记(五): Feature Crosses

    目录 Feature Crosses Encoding Nonlinearity Kinds of feature crosses Glossay Crossing One-Hot Vectors P ...

  5. Bootstrap 模态框 禁止点击空白关闭模态框事件

    在模态框的div中加上 aria-hidden="true" data-backdrop="static" <div class="modal ...

  6. ActiveXObject

    只有IE浏览器才支持这个构造函数,可以用这个来判断,当前是否为IE浏览器 var isIE=!!window.ActiveXObject; 在IE的不同版本下,要创建XHR对象,也需要通过这个构造函数 ...

  7. 代理工具--fiddle

    正则匹配 1)前缀为“EXACT:”表示完全匹配:只有match=rules时,才匹配 2)无前缀表示基本搜索,表示搜索到字符串就匹配:只要match中包含了rules的字符串,即可 3)前缀为“NO ...

  8. linux中怎样关闭ICMP回应功能

    引用自:http://blog.csdn.net/qq844352155/article/details/49700121 linux中怎样关闭ICMP回应功能   输入:   echo 1 > ...

  9. opencv和numpy的安装

    近日,学姐让我们切割图片,查了一下资料,发现我需要安装opencv和numpy.但是在安装过程中却出现了很多小问题,我在此结合自和自己的安装经验和网上查找的资料,做一个笔记. 1.opencv的安装 ...

  10. Applied Nonparametric Statistics-lec7

    Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/9 经过前面的步骤,我们已经可以判断几个样本之间是否 ...