A1071 Speech Patterns (25 分)
一、技术总结
- 开始拿到这道题目时,思考的是我该如何区分它们每一个单词,不知道这里还是要学习得知在cctype头文件中有一个函数用于查看是否为09、az、A~Z,就是isalnum(),又因为题目中要求不区分大小写,有一个函数tolower(),toupper()要学会合理利用。
- 然后就是使用map技术了,默认初始化为0如果是string,int,可以直接mp[]++;
- 然后就是键值和值mp->first,mp->second;
二、参考代码
#include<iostream>
#include<map>
#include<cctype>
using namespace std;
int main(){
string t, s;
map<string, int> mp;
getline(cin, s);
for(int i = 0; i < s.length(); i++){
if(isalnum(s[i])){
s[i] = tolower(s[i]);
t += s[i];
}
if(!isalnum(s[i]) || i == s.length()-1){
if(t.length() != 0) mp[t]++;
t = "";
}
}
int maxn = 0;
for(auto it = mp.begin(); it != mp.end(); it++){
if(it->second > maxn){
maxn = it->second;
t = it->first;
}
}
cout << t << " " << maxn;
return 0;
}
A1071 Speech Patterns (25 分)的更多相关文章
- 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 ...
- 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))
题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...
- 【算法笔记】A1071 Speech Patterns
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 1071 Speech Patterns (25)(25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 1071. Speech Patterns (25)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- A1071. Speech Patterns
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 (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
随机推荐
- Kali Linux configuration "Ettercap"
Xx_Instroduction Ettercap is a man-in-the-middle attack(MITM) tool,kali take this tool,so,use front ...
- VUE添加网站favicon.ico图标
1.修改webpack.dev.conf文件 webpack.prod.conf文件 new HtmlWebpackPlugin({ filename: 'index.html', templat ...
- Linux发行版的系统目录名称命名规则以及用途
linux各种发行版都遵循LSB(Linux Stadards Base)规则,使用一致的相关的基础目录名称,使用根目录系统结构(root filesystem),使用FHS(Files Hierar ...
- spring data JPA entityManager查询 并将查询到的值转为实体对象
spring data JPA entityManager查询 并将查询到的值转为实体对象 . https://blog.csdn.net/qq_34791233/article/details/81 ...
- VUE中 $on, $emit, v-on三者关系
VUE中 $on, $emit, v-on三者关系 每个vue实例都实现了事件借口 使用$on(eventName)监听事件 使用$emit(eventName)触发事件 若把vue看成家庭(相当于一 ...
- 基于python的yaml配置文件使用方法
一.介绍 YAML是一种简洁的非标记语言 YAML以数据为中心,使用空白.缩进.分行组织数据,从而使表达更加简洁易懂 二.基本规则 大小写敏感 使用缩进表示层级关系 禁止使用Tab缩进,只能使用空格键 ...
- java基础(4):引用数据类型、流程控制语句
1. 引用数据类型 1.1 Scanner类 我们要学的Scanner类是属于引用数据类型,我们先了解下引用数据类型. 引用数据类型的使用: 与定义基本数据类型变量不同,引用数据类型的变量定义及赋值有 ...
- 彻底理解volatile,领悟其中奥妙
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- django中使用pandas Django-pandas
在django中使用pandas操作django的ORM查询出来的QuerySet对象,可以使用插件django-pandas. 截止教程书写时间,django-pandas已发布到0.6.1. 依赖 ...
- css网页布局模板
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...