• [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. 每两个不同人之间的所有对话算作“一段对话”。
  • 输入
  • 输入仅包含一组数据,每行是一句对话,格式为: 
    人名1->人名2: 一句话.
    每行最多包含 1000 个字符,最多 100 行。
  • 输出
  • 输出“止于呵呵”的对话段落所占的百分比,四舍五入到最近的整数。输入数据保证答案不会
    同时和两个整数最近。
  • 样例输入
    1. A->B: Hello!
    2. A->C: Hi!
    3. B->A: Hehe
    4. B->D: Hei!
    5. D->B: How are you?
    6. A->C: Hi???
    7. A->C: Are you there?
    8. B->D: Hehehei!
    9. D->B: What does hehehei mean?
    10. F->E: I want to hehehehehe yah.
  • 样例输出
    1. 50%
  • 提示
    1. 样例解释
    2. A B 之间的最后一句话是"Hehe".
    3. A C 之间的最后一句话是"Are you there?".
    4. B D 之间的最后一句话是"What does hehehei mean?".
    5. E F 之间的最后一句话是"I want to hehehehehe yah". 最后第一段和最后一段话是“止于呵呵”的(注意最后一段对话是以呵呵的变种结束),因此 比例是 50%。

map记录每一场对话,重定向来判断每句是否出现hehe。

代码:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstdlib>
  4. #include<sstream>
  5. #include<cstring>
  6. #include<cstdio>
  7. #include<string>
  8. #include<deque>
  9. #include<cmath>
  10. #include<queue>
  11. #include<set>
  12. #include<map>
  13. using namespace std;
  14. typedef long long LL;
  15. #define INF 0x3f3f3f3f
  16. inline int ishehe(string &s)
  17. {
  18. int len=s.size();
  19. if(len%2!=0||len<=2)
  20. return 0;
  21. for (int i=0; i<len; i++)
  22. {
  23. s[i]=tolower(s[i]);
  24. }
  25. for (int i=0; i<len; i+=2)
  26. {
  27. if(!(s[i]=='h'&&s[i+1]=='e'))
  28. return 0;
  29. }
  30. return 1;
  31. }
  32. inline string change(string &s)
  33. {
  34. string t,a,b;
  35. int len=s.size();
  36. for (int i=0; i<len; i++)
  37. {
  38. if(s[i]=='-'&&s[i+1]=='>')
  39. {
  40. s[i]=' ';
  41. s[i+1]=' ';
  42. }
  43. if(s[i]==':')
  44. s[i]=' ';
  45. }
  46. istringstream sin(s);
  47. sin>>a>>b;
  48. if(a<b)
  49. {
  50. t=t+a+b;
  51. }
  52. else
  53. {
  54. t=t+b+a;
  55. }
  56. return t;
  57. }
  58. int main(void)
  59. {
  60. string name,remark,sho,tname;
  61. int cnt=0;
  62. map<string,int>pos;
  63. map<string,int>::iterator it;
  64. while (getline(cin,name,' '))
  65. {
  66. getline(cin,remark);
  67. istringstream ssin(remark);
  68. tname=change(name);
  69. pos[tname]=0;
  70. while (ssin>>sho)
  71. {
  72. if(ishehe(sho))
  73. {
  74. pos[tname]=1;
  75. break;
  76. }
  77. }
  78. }
  79. for (it=pos.begin(); it!=pos.end(); it++)
  80. {
  81. if(it->second==1)
  82. {
  83. cnt++;
  84. }
  85. }
  86. printf("%.0lf%%\n",cnt*1.0*100/pos.size());
  87. return 0;
  88. }

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. fork新建进程

    #include <sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdio.h> ...

  2. Asp.Net Core 进阶(四)—— 过滤器 Filters

    一.介绍 Asp.Net Core Filter 使得可以在请求处理管道的特定阶段的前后执行代码,我们可以创建自定义的 filter 用于处理横切关注点. 横切关注点的示例包括错误处理.缓存.配置.授 ...

  3. USACO08FEB Hotel

    题目传送门 线段树维护区间 线段树结构体 struct zzz{ int l,r,mi; //l为以左端点的为起点的最长子串 //r为以右端点为终点的最长子串 //mi是区间内部的最长子串 }tree ...

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

  5. shell脚本,awk里面的BEGIN讲解。

    解释: BEGIN{}这个特殊的pattern最常用的就是 变量赋值. BEGIN这个pattern就是文件没开始读的时候 执行 awk 'BEGIN{FS=":";OFS=&qu ...

  6. 01_1_jdom调用xml文件

    01_1_jdom调用xml文件 1. 导入jdom.jar包 2. xml文件内容 test.xml <?xml version="1.0" encoding=" ...

  7. 01_3_查询指定id的单个对象

    01_3_查询指定id的单个对象 1. 映射文件配置如下信息 <select id="selectStudentById" resultClass="Student ...

  8. tensorflow目标检测API之建立自己的数据集

    1 收集数据 为了方便,我找了11张月儿的照片做数据集,如图1,当然这在实际应用过程中是远远不够的 2 labelImg软件的安装 使用labelImg软件(下载地址:https://github.c ...

  9. tensorflow目标检测API安装及测试

    1.环境安装配置 1.1 安装tensorflow 安装tensorflow不再仔细说明,但是版本一定要是1.9 1.2 下载Tensorflow object detection API  下载地址 ...

  10. 设置通过Maven创建的工程的JDK的版本,更改conf/settings.xml

    eclipse提示警告如下: Build path specifies execution environment J2SE-1.5. There are no JREs installed in t ...