PATA 1071 Speech Patterns.
2024-09-01 00:47:55
#include <bits/stdc++.h>
using namespace std;
bool check(char c)//检查是否为字母或数字
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9')
return true;
else
return false;
}
int main()
{
map<string,int> count;
string str;
getline(cin,str);
int i = 0;
while(i<str.length())
{
string word;
while(i<str.length()&&check(str[i]))
{
if(str[i]>='A'&&str[i]<='Z'){ //大写统一改为小写
str[i] += ('a'-'A');
}
word += str[i]; //字符拼接 +
i++;
}
if(word != ""){
if(count.find(word)==count.end()) count[word]=1; //这单词还没出现过,计数为1
else count[word]++;
}
while(i<str.length()&&!check(str[i])) //遇到其它字符跳过
{
i++;
}
}
string ans;
int MAX=0;
for(map<string,int>::iterator it=count.begin();it != count.end();it++) //只能用!=,而不能用<end()
{
if(it->second>MAX)
{
ans = it->first;
MAX = it->second;
}
}
cout<<ans<<" "<<MAX<<endl;
return 0; }
最新文章
- 深入理解JVM内幕(转)
- php变量 写时改变 写时复制
- Train Problem I hdu 1022(栈)
- js 调整排序
- C++学习20 虚基类详解
- IOS AutoLayout 文章
- Sublime Text 2 插件
- python手记(30)
- 适应手机端的jQuery图片滑块动画
- UVA 12113 Overlapping Squares
- JavaScipt中对DOM的理解
- python+requests+unittest API接口测试
- Cypher语法
- [BZOJ 3329]Xorequ
- ubuntu下安装php扩展
- mysql 通过查看mysql 配置参数、状态来优化你的mysql
- axios的学习与使用
- inno setup 软件打包
- reduce 之 mixin实现
- js阻止默认事件、拖拽等等
热门文章
- 从零开始学习 asp.net core 2.1 web api 后端api基础框架(四)-创建Controller
- 安装在谷歌axure小工具
- spring boot 集成mybatis报错Missing artifact
- wpf采用Xps实现文档显示、套打功能
- WPF学习笔记:(一)数据绑定与DataContext
- Bootstrap 反色导航条
- VisualSVN-6.0.1Patch just for VS2017补丁原创发布
- Qt侠:像写诗一样写代码,玩游戏一样的开心心情,还能领工资!
- SQLServer 复制中移除和添加发布而不初始化所有项目
- c#实现golang 的channel