又是考输入输出

#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. Hello QT(译)

    简评:PySide2 是 QT 官方出品,值得期待 PySide2 第一个技术预览版快要发布了,在此给出一个简单的例子,来展示它将如何打开 Python世界的大门. 下面我们将使用 QWidgets ...

  2. XPath语法使用的一些心得

    XPath语法还是很强大的,支持一些函数和操作符,方便操作,但是因为版本的原因可能有的函数只能在XPath2(2007)里使用,而不能在XPath1(1999)中使用,比如函数 ends-with(s ...

  3. php-elasticsearch bulk批量插入数据

    1.单条插入 <?php include '../vendor/Elasticsearch/autoload.php'; $a['hosts'] = array( #需要用户名时 http:// ...

  4. [开源JVM] yvm - 自制Java虚拟机

    中文 | English | | | YVM是用C++写的一个Java虚拟机,现在支持Java大部分功能,以及一个基于标记清除算法的并发垃圾回收器. 不过还有很多bug等待修复. 感兴趣的朋友pull ...

  5. Jenkins添加maven插件

    1.1.1 安装Maven插件 我们要使用Jenkins+Maven对Java项目进行构建,需要安装Maven Project Plugin,具体安装过程请参考插件管理部分 1.1.2 3.Linux ...

  6. Dev中gridControl修改列为按钮

    (1)点击Run Designer (2)点击要修改的列,把列的ColumnEdit属性设置为RepositoryItemButtonEdit (3)把TextEditStyle属性设置为HideTe ...

  7. 漫谈TCPIP协议原理

    一.每次说道TCPIP协议,有能说会道者,总爱说三次握手,什么意思? 顾名思义,假设有两个机器A和B 1.当A发送给B一个包的时候,B接收到了,这个时候,B有两个选择,要么将包数据放入缓存,等待处理, ...

  8. (转)expect命令脚本语言介绍及生产实践

    原文:http://www.fblinux.com/?p=526 Expect介绍 expect是一个用来实现自动交互功能的软件套件,是用来实现自动和交互式任务程序进行通信,无需人的手工干预.比如SS ...

  9. (转)Linux企业运维人员常用的150个命令分享

    Linux企业运维人员常用的150个命令分享 原文:http://www.jb51.net/article/127014.htm 本文将向大家介绍Linux企业运维人员常用的150个命令,如有不足之处 ...

  10. Kafka 0.9 新消费者API

    kafka诞生之初,它自带一个基于scala的生产者和消费者客户端.但是慢慢的我们认识到这些API有很多限制.比如,消费者有一个“高级”API支持分组和异常控制,但是不支持很多更复杂的应用场景:它也有 ...