1071. Speech Patterns (25)
来源:互联网 发布:成都工作 知乎 编辑:程序博客网 时间:2024/06/16 12:07
用map保存word及次数,由于map自动按字典序保存,最后只要输出第一个和max一样的字符就可以了
#include<iostream>#include<string>#include<vector>#include<map>#include<cctype>#include<algorithm>#pragma warning(disable:4996)using namespace std;int main(){ string str; getline(cin, str); map<string, int> all; string temp; int max = 0; for (auto x : str)//处理字符,并计算出最大出现次数 { if ((x >= '0'&&x <= '9') ||//对于0-9,a-z,A-Z的字符增加在当前temp末尾(小写) (x >= 'a'&&x <= 'z') || (x >= 'A'&&x <= 'Z')) temp += tolower(x); else if (!temp.empty())//对于非以上字符,判断temp是否为空字符,若不为空,保存 { if (++all[temp] > max) max = all[temp]; temp=""; } } if(!temp.empty()) if (++all[temp] > max) max = all[temp];//处理最后剩余的字符 for (auto it = all.begin();it != all.end();it++)//输出 if (it->second == max) { printf("%s %d\n", it->first.c_str(), it->second);exit(0); }}
0 0
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- 1071. Speech Patterns (25)
- jdk与jre的区别,作用详解!
- 获取系统时间代码块
- Glusterfs下读写请求的处理流程
- 递归从尾到头打印链表每个节点的值
- Android 5.0 如何正确启用isLoggable
- 1071. Speech Patterns (25)
- javascript---BOM
- 使用Hibernate 实现数据添加功能
- Codeforces Round #146 (Div. 2)-C. LCM Challenge
- 实体标签 媒体标签 超链接标签 图片标签
- ViewPager 加载Fragment oncreatview() 方法重复调用最简单解决方案
- Beehive UVALive - 7528 (找规律+数学思维)
- Android Gradle多渠道和自动化打包(深入篇)
- SQL中datetime和timestamp的区别