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进行读取 ...
随机推荐
- Leetcode 237 Delete Node in a Linked List 链表
如题 删除是要注意让现在的链表等于下一个链表的值 class Solution { public: void deleteNode(ListNode* node) { ListNode *nextno ...
- WinForm和WPF颜色对象的转换
原文:WinForm和WPF颜色对象的转换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details ...
- ASP .NET DropDownList多级联动事件
思路 假如有三级省.市.区,先加载出所有省选择省之后,加载出该省所有市选择市之后,加载出该市所有区重新选择省,则清空市和区重新选择市,则清空区想好数据结构,不同的数据结构做法不同 例子 数据结构 pu ...
- 二维码彩色广告招牌的切割制作问题(C#.net下对彩色二维码圆角样式及改进)
原文:二维码彩色广告招牌的切割制作问题(C#.net下对彩色二维码圆角样式及改进) 我们知道,目前二维码还很少用于广告招牌的制作.但随着智能手机越来越普及,互联网等网络的应用也越来越广泛,作为连接物理 ...
- XF 显示网络图像
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- python 识别身份证号码
# !/usr/bin/python # -*-coding:utf-8-*- import sys import time time1 = time.time() from PIL import I ...
- [原译]一步步教你制作WPF圆形玻璃按钮
原文:[原译]一步步教你制作WPF圆形玻璃按钮 图1 1.介绍 从我开始使用vista的时候,我就非常喜欢它的圆形玻璃按钮.WPF最好的一个方面就是允许自定义任何控件的样式.用了一段时间的Micros ...
- qmake 时复制文件(自动在编译前做一些操作,且写在.pro文件里)
有时在编译前需要准备一些文件,例如修改了 QtCreator 的编译输出目录: Build & Run > Default build directory,使用 Promote 后需要在 ...
- huawei 通过BGP的团体属性进行路由控制
网络拓扑 XRV1的配置: =========================================================================== # sysname ...
- GIS基础软件及操作(十)
原文 GIS基础软件及操作(十) 练习十.网络分析 (1) 加深对网络分析基本原理.方法的认识:(2) 熟练掌握ARCGIS下进行道路网络分析的技术方法:(3) 结合实际.掌握利用网络分析方法解决地学 ...