PATA 1071 Speech Patterns.
#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; }
PATA 1071 Speech Patterns.的更多相关文章
- PAT 1071 Speech Patterns[一般]
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 1071 Speech Patterns——PAT甲级真题
1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...
- 1071. Speech Patterns (25)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 1071 Speech Patterns
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 1071 Speech Patterns (25)(25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT Advanced 1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT甲题题解-1071. Speech Patterns (25)-找出现最多的单词
分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 ...
随机推荐
- C++ Primer 学习笔记_104_特殊工具与技术 --嵌套类
特殊工具与技术 --嵌套类 能够在还有一个类内部(与后面所讲述的局部类不同,嵌套类是在类内部)定义一个类,这种类是嵌套类,也称为嵌套类型.嵌套类最经常使用于定义运行类. 嵌套类是独立的类,基本上与它们 ...
- Android获取百度音乐下载音乐和歌词下载链接
首先,你必须通过以下连接下载歌曲: http://box.zhangmen.baidu.com/x?op=12&count=1&title={title}$${author}$$$$ ...
- css3 位置选择器 类似jq的:eq(0)
JQ使用 :eq(位置),可以选择第几个元素 CSS3里面新增了一个用法,:nth-child(位置) 可实现和JQ同样的功能 需要注意的是jq第一个是从0开始,CSS的第一个是从1开始
- PHP获得指定日期所在星期的第一天和最后一天
function getdays($day){ $lastday=date('Y-m-d',strtotime("$day Sunday")); $firstday=date('Y ...
- 怎样解决python dataframe loc,iloc循环处理速度很慢的问题
怎样解决python dataframe loc,iloc循环处理速度很慢的问题 1.问题说明 最近用DataFrame做大数据 处理,发现处理速度特别慢,追究原因,发现是循环处理时,loc,iloc ...
- QString转换为LPTSTR(使用了reinterpret_cast,真是叹为观止,但是也开阔了思路),三篇文章合起来的各种转换方法
醉了,windows下宏定义了很多char类型 LPTSTR .今天,直接使用,qt报错,真TM费事. 将“CPU”转化为wcha_t * QString str = "CPU"; ...
- 问题记录,Release模式和Debug运行效果不一样,Release必须加延时
这个程序大体是这样一个逻辑,通过win32程序与设备交互,主线程先向设备发送命令要求 循环验证 然后一个线程专门负责接收设备返回信息 两边通过全局变量的变化来交流,主线程通过接收线程收到的信息设置界面 ...
- Advanced Installer,搜索注册表,根据注册表选择安装路径
原文:Advanced Installer,搜索注册表,根据注册表选择安装路径 又停了一段时间没有更新了,今天上博客,发现有位朋友就打包的时候需要搜索注册表(不同版本注册表路径不一致,需要搜索多次来确 ...
- 装了VS2005再装IIS,结果出了些小问题 访问IIS元数据库失败
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42 装了VS2005再装IIS,结果出了些小问题访问IIS元 ...
- C#6.0一些特性
1.自动属性初始化的改进 声明属性时可以直接进行初始化 public int id {get;set;}=10; 自动属性是省去了get和set内部的过程,而直接用set;get;这样的语句代替, 把 ...