• [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;
}

最新文章

  1. 关于.NET异常处理的思考
  2. angular2环境搭建
  3. 使用App.config管理数据库连接
  4. html 杂记
  5. 原创:跳坑指南——微信小程序真机预览跟本地不同的问题
  6. ionic实现上拉到底内容提示
  7. ConurrentHashMap和Hashtable的区别
  8. Windows Store App 控件动画
  9. 【Hibernate 9】悲观锁和乐观锁
  10. 【原创】解决鼠标经过子元素触发mouseout,mouseover事件的问题
  11. SQL Server R2 2008中的SQL Server Management Studio 阻止保存要求重新创建表的更改问题的设置方法
  12. 7.2 Database Backup Methods 数据备份方法:
  13. Java拦截器的实现原理
  14. openstack快速复制一台云主机系统
  15. sshfs基于ssh挂载远程目录
  16. cf- Educational Codeforces Round 40 -D
  17. 学习使用scrapy itemspipeline过程
  18. go-micro介绍 摘自https://www.cnblogs.com/s0-0s/p/6874800.html
  19. 介绍——基于类的视图(class-based view)
  20. Interface_GL通过gl_interface导入日记账(案例)

热门文章

  1. Erlang程序设计(第2版)读书笔记(一)
  2. CentOS lvm
  3. axure的基本使用方法(侧边导航栏的制作)
  4. DB2中创建表
  5. SSH程序框架之Spring与HIbernate整合
  6. NSStream实现发送和接受数据
  7. linux系统下的用户文件句柄数限制
  8. 【启发式拆分】bzoj4059: [Cerc2012]Non-boring sequences
  9. MySQL多源复制
  10. C++图书馆管理系统项目中部分功能代码实现(书籍推荐)