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 ...
随机推荐
- UDP与IP分片
一.引言  UDP是简单的面向数据报的运输层协议.UDP不提供可靠性:它负责把应用程序传给IP层的数据发送出去,不保证能导到目的地. 二.UDP首部  端口号表示发送进程和接受进程.由于IP层已经 ...
- 一个python 服务器程序性能分析
该服务器为bono,启动11个进程. 1.设置cprofile 在启动服务的总入口设置cprofile if __name__=="__main__": import cProfi ...
- 2016级算法第五次上机-A.Beihang Collegiate Pronunciation Contest 2017
1065 Beihang Collegiate Pronunciation Contest 2017 思路 在字符串中不断做匹配 找到一个匹配就输出 时间复杂度\(O(n)\) ps.模式串是定长的, ...
- Linux 通过程序名获取进程ID并Kill
#!/bin/bash pids=$(ps -ef | grep XXX| awk '{print $2}') for pid in $pids do echo $pid kill -9 $pid d ...
- 为什么一定要学Go语言
Go语言是谷歌2009发布的第二款开源编程语言.Go语言专门针对多处理器系统应用程序的编程进行了优化,使用Go编译的程序可以媲美C或C++代码的速度,而且更加安全.支持并行进程. 为什么要选择学习Go ...
- Q394 字符串解码
给定一个经过编码的字符串,返回它解码后的字符串. 编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次.注意 k 保证为正整数. 你可 ...
- 【后渗透】PowerSploit
1.下载安装:git clone https://github.com/mattifestation/PowerSploit.git 2.搭建web服务器(如172.16.12.2),将powersp ...
- Flutter Navigator operation requested with a context that does not include a Navigat
如下直接在 MaterialApp 中使用 Navigator 是会报 Navigator operation requested with a context that does not inclu ...
- FileZilla上傳報錯:421 There are too many connections from your internet address
起因:2019年01月27日晚九點左右,想要將一個50MB+的文件夾上傳到阿里雲的虛擬主機上,使用FTP 工具FileZilla,出現了上傳一段時間後提示421 There are too many ...
- js中报错"Maximum call stack size exceeded"解决方法
Uncaught RangeError: Maximum call stack size exceeded 错误直译过来就是“栈溢出”,出现这个错误的原因是因为我进行了递归运算,但是忘记添加判断条件, ...