又是考输入输出

#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm> using namespace std; char buf[]; bool is_alphanumerical(char &ch) {
if (ch >= '' && ch <= '') return true;
if (ch >= 'a' && ch <= 'z') return true;
if (ch >= 'A' && ch <= 'Z') {
ch += 'a' - 'A';
return true;
}
return false;
} int main() { char ch; bool inword = false;
int wpos = ;
int max_count = -; unordered_map<string, int> count;
vector<string> maxs; while(ch = getchar()) {
bool isan = is_alphanumerical(ch);
if (isan) {
if (!inword) {
// new word begin
wpos = ;
inword = true;
}
// append character
buf[wpos++] = ch;
} else {
if (inword) {
// current word end
buf[wpos] = '\0';
string word(buf);
auto iter = count.find(word);
if (iter == count.end()) {
iter = count.insert(make_pair(word, )).first;
}
if (++(iter->second) > max_count) {
max_count = iter->second;
maxs.clear();
maxs.push_back(word);
} else if (iter->second == max_count) {
maxs.push_back(word);
}
inword = false;
}
}
if (ch == '\n') {
break;
}
} sort(maxs.begin(), maxs.end());
int mcount = count.find(maxs[])->second;
printf("%s %d", maxs[].c_str(), mcount);
return ;
}

PAT 1071. Speech Patterns的更多相关文章

  1. PAT 1071 Speech Patterns[一般]

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

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

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

  3. 1071 Speech Patterns——PAT甲级真题

    1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...

  4. PAT Advanced 1071 Speech Patterns (25 分)

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

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

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

  6. PAT甲题题解-1071. Speech Patterns (25)-找出现最多的单词

    分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 ...

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

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

  8. 1071. Speech Patterns (25)

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

  9. 1071 Speech Patterns

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

随机推荐

  1. Docker容器基础认知

    ## 一. [docker](http://www.itxdm.me/archives/tag/docker/)概念 [Docker](http://www.itxdm.me/wp-content/p ...

  2. SQLServer XML

    OPENXML 参见:OPENXML (SQL Server) | Microsoft Docs SQL For XML 参见:FOR XML (SQL Server) | Microsoft Doc ...

  3. 可变参数中size_t遇见的问题

    在修改php扩展Trie时,出现了一个小bug PHP_FUNCTION(trie_filter_load) { Trie *trie; char *path; int path_len; if (z ...

  4. 2016级算法第一次练习赛-A.群鸦的盛宴

    858 群鸦的盛宴 题目链接:https://buaacoding.cn/problem/858/index 思路 本题乍一眼看过去,你可能会想到使用一个二维数组A[51][51]来记录从i到j的路线 ...

  5. css3 实现 tooltip

    /* START TOOLTIP STYLES */ [tooltip] { position: relative; /* opinion 1 */ } /* Applies to all toolt ...

  6. linux下普通用户添加 sudo 免密码

    在使用普通用户登录的时候,会经常使用sudo指令执行一些操作,有时候感觉输入密码比较繁琐,特别是需要设置一些开机启动的时候操作,而这些操作往往就需要sudo指令,如果没有免密的话,在使用普通用户登录的 ...

  7. 练习 DOUBLE INSERT

      练习 DOUBLE INSERT 目标:从一张表取数据插入到另一张表中,此外需要为插入的目标表做一个应用级的日志表,也就是说在插入目标表的同时,还需要将相同的数据插入到日志表中. 在案例一中,我们 ...

  8. c# 水晶报表使用说明

    水晶报表介绍 水晶报表是 vs 早期版本自带的一款报表控件.vs2017不自带水晶报表,需要自行安装.虽然水晶报表是收费控件,但是微软已经付过钱了,所以vs自带的水晶报表可以直接使用. 如果项目是 . ...

  9. 浅谈Supermap iClient for JavaScript 弹窗类

    地图作为信息的载体和呈现方式,是GIS的重要组成部分,它是一个浏览信息的窗口,在信息日益发达的今天 ,各种地图应用如雨后春笋一般出现在大众眼前,而不是像以往一样太过局限于专业的领域.而弹窗,是作为地图 ...

  10. 【ExtJS】关于标准模块化封装组件

    在此之前,自己封装自定义控件用的是这样的方式: Ext.define('My.XXX',{ extend: 'Ext.YYY', xtype: 'ZZZ', . . . items:[ ... ] } ...