【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))
题意:
输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写)。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string word;
map<string,int>mp;
string s;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string x;
getline(cin,x);
int n=x.size();
for(int i=;i<n;++i)
if((x[i]>='A'&&x[i]<='Z')||(x[i]>='a'&&x[i]<='z')||(x[i]>=''&&x[i]<='')){
if(x[i]>='A'&&x[i]<='Z')
x[i]=x[i]-'A'+'a';
word.push_back(x[i]);
}
else if(word!=""){
++mp[word];
word.clear();
}
if(word!=""){
++mp[word];
word.clear();
}
int mx=;
for(auto it:mp)
if(it.second>mx){
mx=it.second;
s=it.first;
}
cout<<s<<" "<<mx;
return ;
}
【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))的更多相关文章
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- PAT Advanced 1071 Speech Patterns (25 分)
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甲级——A1071 Speech Patterns
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
- PAT 甲级 1146 Topological Order (25 分)(拓扑较简单,保存入度数和出度的节点即可)
1146 Topological Order (25 分) This is a problem given in the Graduate Entrance Exam in 2018: Which ...
- PAT 甲级 1063 Set Similarity (25 分) (新学,set的使用,printf 输出%,要%%)
1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be ...
- PAT 甲级 1059 Prime Factors (25 分) ((新学)快速质因数分解,注意1=1)
1059 Prime Factors (25 分) Given any positive integer N, you are supposed to find all of its prime ...
- PAT 甲级 1051 Pop Sequence (25 分)(模拟栈,较简单)
1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ord ...
随机推荐
- centos7安装启动firefox
1.卸载系统之前Firefox sudo yum erase firefox 2.安装firefox命令: sudo yum install firefox 3.驱动下载地址: https://git ...
- C++-函数与指针的关系(回调函数)
1.函数类型 C语言中的函数有自己特定的类型 函数的类型由返回值,参数类型和参数个数共同决定 ★ int add(int i, int j)的类型为int(int, int) C语言中通过typede ...
- linux 中对 mysql 数据表的基本命令
显示数据表的结构 describe 表名; 建表 use 库名: create table 表名(字段设定列表): 将表中记录清空 delete from 表名; 删表 drop table 表名:
- linux - mysql:注意事项
1.mysql和orcal数据中的数据类型不一致,比如:mysql中没有类型varchar2.number 2.mysql环境中的命令后面都带一个分号作为命令结束符 - “:”
- 执行PDB的PITR恢复失败的说明
Oracle 12.1版本中,UNDO表空间仅存在CDB级别(共享UNDO),来自于AskScuti博客园. Oracle 12.2版本开始,UNDO表空间同时可以存在每个PDB级别(本地UNDO). ...
- LitElement(六)生命周期
1.概述 基于LitElement的组件通过响应观察到的属性更改而异步更新. 属性更改是分批进行的,如果在请求更新后,更新开始之前,发生更多属性更改,则所有更改都将捕获在同一次更新中. 在较高级别上, ...
- 剑指offer 面试题56. 数组中只出现一次的两个数字
题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 方法1:用set记录出现过的数字 class Solution { public: void F ...
- rancher布控集群启动失败的猜测
rancher布控集群启动失败的猜测 待办 报告缺少某个文件.多线程启动任务部署的时候某些线程跑在前边了, 导致问题出现 或者 网络问题出现超时,导致出现此类报错 或者 内存不足导致问题出现报错 或者 ...
- [HDU5382]GCD?LCM!
Description HDU5382 会吗?不会! 设\(F(n)=\sum\limits_{i = 1}^{n}\sum\limits_{j=1}^{n}[lcm(i,j)+gcd(i,j)\ge ...
- HTML连载60-水平居中与设计一个团购界面
一.水平居中 1.margin:0 auto在绝对定位中就失效了 2.如何让绝对定位的元素水平居中? 只需要设置绝对定位元素的left:50%:然后再设置绝对定位元素的margin-left:-元素宽 ...