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进行读取 ...
随机推荐
- bootstrap学习之路
接触bootstrap也半年有余,从一开始不知道如何使用,到知道其各个模块的具体功能,再到提炼哪些使用的比较多,再此又体会到bootstrap源码的精髓,通过oocss写的类使其感觉更有易用性,开始本 ...
- Jenkins 部署
1 修改jenkins的根目录,默认地在C:\Documents and Settings\AAA\.jenkins . .jenkins ├─jobs│ └─JavaHelloWorld│ ...
- 新版本MenuDemo——使用Duilib模拟Windows本机菜单
相信玩Duilib朋友已经开始期待一个很长的文章.由于我的文章在一周前公布--"无焦点窗体的实现"里面提到了无焦点窗体在菜单里面的应用,并承诺大家,写一个关于Menu实现的Demo ...
- wpf版权限管理
之前做的权限管理是基于Mvc的Web项目,模型.仓储及业务层次分明,6月中旬开始使用这套之前完成的底层架构开发Wpf版本的权限管理软件(后续将成熟企管系统进行抽象业务加入到该版本中,向企管系统靠近) ...
- C#实现进程内存信息获取
using System.Collections.Generic;using System.Runtime.InteropServices;using System;using System.Diag ...
- ios技术支持网址
如有任何问题可以留言: 邮箱地址:cccliche@outlook.com
- Java之nio性能比较
结果:used time:53574684used time:1800077620used time:12563690可见MappedByteBuffer读写数据是最快的, 其次是FileChanne ...
- Emgu-WPF 激光雷达研究-移动物体跟踪
原文:Emgu-WPF 激光雷达研究-移动物体跟踪 接前两篇博客: 激光雷达数据解析并绘制雷达图 https://blog.csdn.net/u013224722/article/details/80 ...
- abp.message
abp.message.success(app.localize('SomeMessage'), app.localize('Title')) .done(function() { //do some ...
- v-charts显示标题
使用v-charts的时候,如果要显示标题需要以下操作 1. 加入:title props <ve-pie :title="chartTitle" :data="c ...