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 ...
随机推荐
- XSS劫持cookie登录
<script>alert (document.cookie)</script> 获取cookie 实验环境用的DVWA 先用系统账号登录,admin password ...
- nmcli详解
1. nmcli 安装 [root@liujunjun ~]# yum install -y NetworkManager CentOS7默认已安装了 2. nmcli 基本选项 选项 作用 -t 简 ...
- Jmeter脚本录制攻略
基于Apache JMeter(5.2.1) 首先在TestPlan里添加一个HTTP代理服务武器: 设置端口,在目标控制器里选择线程组. 在Chrome浏览器里设置代理: 点击启动按钮后,在浏览器登 ...
- vue 中的小知识点
1)使用is解决小bug <!DOCTYPE html><html lang="en"> <head> <meta charset=&qu ...
- 《Google软件测试之道》
Google软件测试之道 Google对质量的理解 质量不等于测试,即质量不是被测出来的 开发和测试应该并肩齐驱,测试就是开发过程中不可缺少的一部分 质量是一种预防行为而不是检测 Google对软件测 ...
- ASP.NET页面缓冲
整页缓存<% OutPutCache Duration=5 VaryByParam="none" %>Duration是缓冲时间 参数可以有多个 在varyByPara ...
- java 与 iOS 平台概念比较
java oc/swift jvm iphone jre runtime? jdk ios SDK spring xcode 生成的应用模版 服务器(tomcat) 系统的事件调度派发部分 class ...
- 基于STM32F429的ADS1115驱动程序
1.ADS1115中文资料:https://wenku.baidu.com/view/8bab101feef9aef8941ea76e58fafab069dc44e7.html?rec_flag=de ...
- 《ServerSuperIO Designer IDE使用教程》- 7.增加机器学习算法,通讯采集数据与算法相结合。发布:4.2.5 版本
v4.2.5更新内容:1.修复服务实例设置ClearSocketSession参数时,可能出现资源无法释放而造成异常的情况.2.修复关闭宿主程序后进程仍然无法退出的问题.2.增加机器学习框架.3.优化 ...
- RandomAccessFile()实现用户注册功能, 新增,查询,更新
package seday03.raf;import java.io.IOException;import java.io.RandomAccessFile;import java.util.Arra ...