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 ...
随机推荐
- 使用shell脚本查看数据库负载情况
原创 Oracle 作者:jeanron100 时间:2014-05-23 08:56:26 8912 2 平时在查看数据库的问题时,会有种迷茫的感觉,如果没有任何人反馈问题,基本上没有主动查找问 ...
- 11.2 Data Guard Physical Standby Switchover Best Practices using SQL*Plus (Doc ID 1304939.1)
11.2 Data Guard Physical Standby Switchover Best Practices using SQL*Plus (Doc ID 1304939.1) APPLIES ...
- Nginx基础知识点总结和优化项
1.什么是Nginx? Nginx是一个高性能的HTTP和反向代理服务器,常用于做负载均衡服务器 2.为什么要用Nginx?跨平台.配置简单非阻塞.高并发连接:处理2-3万并发连接数,官方监测能支持5 ...
- Linux系统学习 十四、VSFTP服务—配置文件解析、客户端使用
3.配置文件解析 默认配置选项: 一般情况下不允许匿名用户登录 全局配置选项:(手工添加) listen_address=192.168.4.1 #设置监听地址 listen_ ...
- Excel上下标如何设置?
Excel表格怎么设置上下标?Excel上下标设置技巧 在21世纪的我们,平时的工作和学习中,经常会使用到一些专业的文档,比如方程式.数据的公式和科学计数等,其中均会涉及到许多的上下标符号输入以及使用 ...
- 苹果 macOS 安装 Source Code Pro
1. 下载 到 Source Code Pro 的 GitHub 官网下载:https://github.com/adobe-fonts/source-code-pro 点击 GitHub 中 ...
- HttpClient发起Http/Https请求工具类
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpcl ...
- Vue 03
目录 组件 组件的分类 组件的特点 组件的使用 组件传参-父传子 组件传参-子传父 组件 组件就是html, css和js文件的集合体, 实现对代码的复用, 组件就是vue对象 组件的分类 根组件 & ...
- PHP Swoole与TCP三次握手
握手常见问题 1.连接拒绝 2.Operation now in progress 多是因为丢包.错误ip.backlog满了&阻塞&tcp_abort_on_overflow=0 3 ...
- ASP.NET Core 2.2 WebApi 系列【二】使用EF CodeFirst创建数据库
Code First模式 Code First是指"代码优先"或"代码先行". Code First模式将会基于编写的类和配置,自动创建模型和数据库. 一.准备 ...