一、技术总结

  1. 开始拿到这道题目时,思考的是我该如何区分它们每一个单词,不知道这里还是要学习得知在cctype头文件中有一个函数用于查看是否为09、az、A~Z,就是isalnum(),又因为题目中要求不区分大小写,有一个函数tolower(),toupper()要学会合理利用。
  2. 然后就是使用map技术了,默认初始化为0如果是string,int,可以直接mp[]++;
  3. 然后就是键值和值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 分)的更多相关文章

  1. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  2. PAT Advanced 1071 Speech Patterns (25 分)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  3. 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))

    题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...

  4. 【算法笔记】A1071 Speech Patterns

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  5. 1071 Speech Patterns (25)(25 分)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  6. 1071. Speech Patterns (25)

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  7. A1071. Speech Patterns

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  8. PAT甲级——A1071 Speech Patterns

    People often have a preference among synonyms of the same word. For example, some may prefer "t ...

  9. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

随机推荐

  1. js-02-循环语句

    循环语句分类{ for while do ( ) while } 一.for循环语句和for循环的嵌套 for循环格式eg: <script> var sim = 0; for(var i ...

  2. Mac-关于升级macOS Catalina后,终端试用问题

    xcrun: error 在终端输入 git clone *****后,提示: xcrun: error: invalid active developer path (/Library/Develo ...

  3. 创建以.xxx开头的文件夹的方法

    在windows下创建以.xxx开头的文件夹时,点击确认,系统提示“必须键入文件名”. 最方便的方法: (1)新建文件夹 (3)在文件名.xxxxx后再加一个.,也就是把文件名改成这样子:.XXXXX ...

  4. Kali Linux上外网

    第一部分 攻击者杀链 第一章  走进Kali Linux 镜像准备:32位kali linxu 2019(之前下载好了,按书上的版本太低了要重新配置好多东西就用最新版了) , win XP 前两章照着 ...

  5. Nginx + FastCGI + Django在windows上部署及nginx常用命令

    一般应用都是部署在linux系统上,不会在windows上部署,emmm..所以有兴趣的就瞧瞧吧哈哈 nginx工作原理: nginx用于处理静态文件,动态部分经由fastcgi .scgi或uWSG ...

  6. CF 1114D(538,div2) Flood Fill

    https://codeforces.com/contest/1114/problem/D 题目 给一串数字,首先选择一个位置,类似于画图,然后每一轮按照以下步骤: 可以将这个位置所在的连通块改成其他 ...

  7. Java之ArrayList类(集合)

    集合的由来 我们想存储多个数据,选择的容器可以是数组.而数组的长度是固定的,无法适应数据变化的需求.为了解决这个问题,Java提供了另一个容器 java.util.ArrayList 集合类,让我们可 ...

  8. Jrebel实现tomcat热部署,遇到的问题以及解决办法,详解

    我的安装的详细过程: 下载Jrebel:  https://github.com/ilanyu/ReverseProxy/releases/tag/v1.4 我的是winx64,所以选择如下的: 下载 ...

  9. 四面快手、终拿Offer,想告诉你的一些事情

    本篇面经来自于群里粉丝朋友的分享,希望对你有所帮助! 快手高开及以上职级面试 是没有笔试或者机试的,所以从第一轮开始就是直接面对面试官. 一轮 主要考察对Java基础的理解和深入程度. Spring ...

  10. goroutine,channel

    Go语言中有个概念叫做goroutine, 这类似我们熟知的线程,但是更轻. 以下的程序,我们串行地去执行两次loop函数: package main import "fmt" f ...