【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 ...
随机推荐
- C语言-const和volatile深度分析
1.const只读变量 const修饰的变量是只读的.本质还是变量 const修饰的局部变量在栈上分配空间 const修饰的全局变量在全局数据区分配空间 const只在编译期有用,在运行期无用 con ...
- python3 yield实现假的多并发
import time def fun1(): while True: print("fun1") time.sleep(0.1) yield def fun2(): while ...
- 实用 SQL 语句
1. 创建 1.1 创建数据库 语法:create database db_name 示例:创建应用数据库 awesome_app sqlcreate database `awesome_app` 复 ...
- SpringCloud Netflix Hystrix
Hystrix的一些概念 Hystrix是一个容错框架,可以有效停止服务依赖出故障造成的级联故障. 和eureka.ribbon.feign一样,也是Netflix家的开源框架,已被SpringClo ...
- Java-类的生命周期浅析
简述:Java虚拟机为Java程序提供运行时环境,其中一项重要的任务就是管理类和对象的生命周期.类的生命周期.类的生命周期从类被加载.连接和初始化开始,到类被卸载结束.当类处于生命周期中时,它的二级制 ...
- AcWing 874. 筛法求欧拉函数
#include<bits/stdc++.h> using namespace std; typedef long long ll; ; int primes[N],cnt; int ph ...
- 题解【CJOJ1071/UVA】硬币问题
P1071 - [Uva]硬币问题 Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为S?输出硬币数目 ...
- 题解【CJOJ1070/UVA】嵌套矩形
P1070 - [Uva]嵌套矩形 Description 有 n 个矩形,每个矩形可以用两个整数 a, b 描述,表示它的长和宽.矩形 X(a, b) 可以嵌套在矩形 Y(c, d) 中当且仅当 a ...
- selenium参数化-ddt模块
DDT介绍: DDT(数据驱动测试)允许您通过使用不同的测试数据运行一个测试用例来使其倍增,并使它显示为多个测试用例.要使用DDT需要安装,安装命令:pip install ddt 使用方法: dd. ...
- unittest学习5-断言
unittest提供了以下断言方式: 方法 检查 新进 assertEqual(a, b) a == b assertNotEqual(a, b) a != b assertTrue(x) b ...