PAT 1071. Speech Patterns
又是考输入输出
#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的更多相关文章
- PAT 1071 Speech Patterns[一般]
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...
- PAT 甲级 1071 Speech Patterns (25 分)(map)
1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For ex ...
- 1071 Speech Patterns——PAT甲级真题
1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...
- PAT Advanced 1071 Speech Patterns (25 分)
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 ...
- PAT甲题题解-1071. Speech Patterns (25)-找出现最多的单词
分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 ...
- 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))
题意: 输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写). AAAAAccepted code: #define HAVE_STRUCT ...
- 1071. Speech Patterns (25)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- 1071 Speech Patterns
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
随机推荐
- python 强大的工具
numpy Python科学计算的基础包 安装工具 pip3 install numpy pandas包含了高级的数据结构和操作工具,它们使得Python数据分析更加快速和容易. 安装工具 pip3 ...
- Web项目通过Maven部署到Tomcat的错误。
一直提示: Maven Build的时候,一直提示一个关键错误 Cannot invoke Tomcat manager: Error writing to server 找了网上提示说应该先启动To ...
- Flexbox(弹性盒子)
CSS3属性:这是一个可以让你告别浮动.完美实现垂直水平居中的新特性. Flexbox是布局模块,而不是一个简单的属性,它包含父元素和子元素的属性. 属性介绍: 创建Flex容器 .container ...
- MIUI7系统如何刷入开发版启用root超级权限
小米的手机或平板不同手机型号通常情况MIUI官方论坛都提供两个不同系统,大概可分为稳定版和开发版,稳定版没有提供root权限管理,开发版中就开启了root权限,很多情况我们需要使用的一些功能强大的AP ...
- Locust 基本使用
Locust 使用Python代码来定义用户行为,用它可以模拟百万级的并发用户来访问系统. 与其他性能工具对比如下: LoadRunner 商业性能测试工具,报告完整,不支持二次开发 开发语言:C/J ...
- 常用sql记录
一.修改字段默认值 alter table 表名 drop constraint 约束名字 ------说明:删除表的字段的原有约束 alter table 表名 add constraint 约 ...
- 3-----Docker实例-安装MySQL
Docker 安装 MySQL 方法一.docker pull mysql 查找Docker Hub上的mysql镜像 runoob@runoob:/mysql$ docker search mysq ...
- 转帖 利用伪元素和css3实现鼠标移入下划线向两边展开效果
原帖地址 https://www.cnblogs.com/yangjunfei/p/6739683.html 感谢分享 一.思路: 将伪元素:before和:after定位到元素底部中间,设置宽度 ...
- linux磁盘分区fdisk命令详解
1.什么是分区? 分区是将一个硬盘驱动器分成若干个逻辑驱动器,分区是把硬盘连续的区块当做一个独立的磁硬使用.分区表是一个硬盘分区的索引,分区的信息都会写进分区表.2.为什么要有多个分区? 防止数 ...
- 与native交互时会出现的问题
1.jsbridge: 可以用jsbridge与native交互,这属于第三方库,前端后端都需要加jsbridge 2.可以直接调用原生的方法,ios: window.webkit.message ...