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 ...
随机推荐
- 恢复 MSSQL bak 文件扩展名数据(下)
恢复 MSSQL bak 文件扩展名数据 一.概念: RESTORE Statements (Transact-SQL) Restores backups taken using the BACKUP ...
- SimpleITK学习(一)基本概念
断断续续使用simpleitk处理CT和X光图片有些时间了,但是学的知识都比较零散,没有形成系统的概念,于是对着SimpleITK的英文文档https://simpleitk.readthedocs. ...
- leetcode 53 最大子序列之和(动态规划)
思路:nums为给定的数组,动态规划: 设 一维数组:dp[i] 表示 以第i个元素为结尾的一段最大子序和. 1)若dp[i-1]小于0,则dp[i]加上前面的任意长度的序列和都会小于nums[i], ...
- Java操作系统剪贴板(Clipboard)复制粘贴
Java操作系统剪贴板(Clipboard)复制粘贴
- JavaScript对象基础知识总结
1.什么叫JavaScript对象? 定义:名值对的集合.简单的讲就是容纳属性值和属性值的容器,这些属性可以是无序的,基本上JavaScript中所有的事物都可以看成对象. 拓展:我们经常说,数组也是 ...
- MSSQL远程连接操作(转)
--遠程連接操作 /****************************************************************************************** ...
- java实现图片文字识别的两种方法
一.使用tesseract-ocr 1. https://github.com/tesseract-ocr/tesseract/wiki上下载安装包安装和简体中文训练文件 window64位安装 ...
- 基于python实现Oracle数据库连接查询操作
使用python语言连接Oracle数据库配置 #coding:utf-8 import cx_Oracle as oracle db=oracle.connect('root/123456@192. ...
- JMeterPlugins插件
一.线程组1.jp@gc - Stepping Thread Group,如下图: 类似loadrunner的场景设置,解释:This Group will start 10 threads:这次的测 ...
- 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题
题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...