【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 ...
随机推荐
- ZooKeeper Distributed lock
https://segmentfault.com/a/1190000016351095 http://www.dengshenyu.com/java/%E5%88%86%E5%B8%83%E5%BC% ...
- 洛谷P1433 吃奶酪
#include<iostream> #include<math.h> using namespace std ; ; int n; bool st[N]; double x[ ...
- LCA 倍增算法模板
. #include <cstring> #include <cstdio> #include <cstdlib> #include <algorithm&g ...
- 【转】git rebase详解
git合并代码方式主要有两种方式,分别为:1.merge处理,这是大家比较能理解的方式.2.rebase处理,中文此处翻译为衍合过程. git rebase操作讲解例子: cd /usr/local/ ...
- 题解【CJOJ1371】[IOI2002]任务安排
P1371 - [IOI2002]任务安排 Description N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分 ...
- biquad filter实现
原始频谱: LPF: HPF: 代码: #include<stdio.h> #include<stdlib.h> #include<errno.h> #includ ...
- linux deploy---旧手机变废为宝
前几天朋友送了我一部红米Note 1s,本来不想要,转念一想,不要白不要,就收了. 拿到之后我就想,这么一个1+8的手机能做什么呢? 翻遍了CSDN和简书,找到了一个性价比不错的方法:给旧手机装上一个 ...
- python接口自动化测试 - requests库的post请求进行文件上传
前言 如果需要发送文件到服务器,比如上传图片.视频等,就需要发送二进制数据. 一般上传文件使用的都是 Content-Type: multipart/form-data; 数据类型,可以发送文件,也可 ...
- 「模板」AC自动机
目录 说明 普通版本 询问更改版 拓扑优化版本 说明 这篇博客只挂模板,具体分析请膜拜大佬 hyfhaha 大佬. 普通版本 题目传送门 #include<cstdio> #include ...
- jsp+servlet实现的验证登陆
可以将业务逻辑处理和视图相分离,使用jsp界面表示视图,使用servlet处理业务逻辑 login.jsp <%@ page language="java" contentT ...