People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for example, whether it's still the same person behind an online avatar.

Now given a paragraph of text sampled from someone's speech, can you find the person's most commonly used word?

Input Specification:

Each input file contains one test case. For each case, there is one line of text no more than 1048576 characters in length, terminated by a carriage return \n. The input contains at least one alphanumerical character, i.e., one character from the set [0-9 A-Z a-z].

Output Specification:

For each test case, print in one line the most commonly occurring word in the input text, followed by a space and the number of times it has occurred in the input. If there are more than one such words, print the lexicographically smallest one. The word should be printed in all lower case. Here a "word" is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end.

Note that words are case insensitive.

字符串相关知识点总结:

·判断是否数字,字母:

#include <cctype>
isnumber(int _c);
isalnum(int _c);
isalpha(int _c);

·大小写转换

#include <cctype>
tolower(int _c);
toupper(int _c);

·字母数字转化

#include <iostream>
#include <sstream>
using namespace std; string s="1234.4";
printf("%f",stof(s)); s="1234";
printf("%d",stoi(s)); a=1234;
cout<<to_string(a);
 #include <string>
#include <iostream>
#include <map>
#include <cctype>
using namespace std; int main(){
string input;
map<string,int> Mp; getline(cin, input);
string tmpStr;
for(int i=;i<input.length();i++){
if(isalnum(input[i])){
tmpStr+=tolower(input[i]);
if(i==input.length()-){
Mp[tmpStr]++;
}
}else{
if(tmpStr.length()) Mp[tmpStr]++;
tmpStr.clear();
}
} string max; int maxTimes;
for(map<string,int>::iterator it=Mp.begin();it!=Mp.end();it++){
if(maxTimes<it->second){
maxTimes=it->second;
max=it->first;
}else if(maxTimes==it->second&&max>it->first){
max=it->first;
}
}
cout<<max<<" "<<maxTimes<<endl;
}

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. 1071. Speech Patterns (25)

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

  5. 1071 Speech Patterns (25)(25 分)

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

  6. PAT Advanced 1071 Speech Patterns (25 分)

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

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

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

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

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

  9. PAT 1071. Speech Patterns

    又是考输入输出 #include <cstdio> #include <cstdlib> #include <string> #include <vector ...

随机推荐

  1. 5.Mysql常用函数

    5.常用函数函数可以进行字符串的处理.数值计算和日期计算等,mysql可以用在SQL(DML)中以增加SQL的功能.5.1 数值函数1. abs(x) 返回x的绝对值select abs(5),abs ...

  2. laravel框架数据迁移

    迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和Laravel 的 schema 构建器结对从而可以很容易地构建应用的数据库表结构.如果你曾经告知小组成员需要手动添 ...

  3. 关于RNA-Seq数据去接头(Adapter)这事需要讲一讲

    关于RNA-Seq数据去接头(Adapter)这事需要讲一讲 RNA-Seq adapter barcode cutadapt 首先来了解一下三个概念: 1.adapter是一段短的序列已知的核酸链, ...

  4. web前端学习笔记:文本属性

    今天的web前端笔记主要讲述文本属性,希望能帮助到正在学习web前端开发的初学者们,废话不多说了,一起来看看文本属性的相关内容吧. 文本属性 文本缩进 将Web页面上的一个段落第一行缩进,这是一种最常 ...

  5. 利用七牛存储7天远程自动备份LINUX服务器

    受服务器空间制约,我们不可能在VPS上每天都备份一份新的网站数据,一是没必要,二是占空间.我们折中一下,采用星期命名,每次备份将覆盖上星期同一天的文件.从而只备份7份数据,不至于占用特别大的空间. 如 ...

  6. .net从网络接口地址获取json,然后解析成对象(二)

    整理代码,这是第二种方法来读取json,然后反序列化成对象的,代码如下: public static Order GetOrderInfo(string _tid, string _orderNo) ...

  7. PHP连接SQLServer2012两例

    首先放上 PHP连接SQLServer的驱动下载地址 http://php.net/manual/zh/ref.pdo-sqlsrv.php 另外PHP for IIS管理工具 大家可以自己搜索一下 ...

  8. HDU 6185(打表代码

    /** @xigua */ #include <cstdio> #include <cmath> #include <iostream> #include < ...

  9. mysql 字符串数值计算 精度丢失

    我进行了一些测试.truncate(abs('414')/100,2)truncate('414'/100,2)truncate('4.14',2)truncate('4.1400',2)都有精度丢失 ...

  10. normalized

    共同点:实现规范化,让一个向量保持相同的方向,但它的长度为1.0,如果这个向量太小而不能被规范化,一个零向量将会被返回. 不同点:Vector3.normalized的作特点是当前向量是不改变的并且返 ...