Source:

PAT A1071 Speech Patterns (25 分)

Description:

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.

Sample Input:

Can1: "Can a can can a can?  It can!"

Sample Output:

can 5

Keys:

  • 字符串处理

Code:

 #include<cstdio>
#include<string>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
map<string,int> mp; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE string s;
getline(cin,s);
transform(s.begin(),s.end(),s.begin(),::tolower);
int i=,j=,cnt=;
while(i<s.size())
{
int j=i;
while(j<s.size() && ((s[j]>=''&&s[j]<='')||(s[j]>='a'&&s[j]<='z')))
j++;
if(j>i)
{
mp[s.substr(i,j-i)]++;
if(mp[s.substr(i,j-i)]>cnt)
cnt = mp[s.substr(i,j-i)];
}
i=j+;
}
for(auto it=mp.begin(); it!=mp.end(); it++)
if(it->second == cnt)
{
printf("%s %d", it->first.c_str(),cnt);
break;
} return ;
}

PAT_A1071#Speech Patterns的更多相关文章

  1. Pat1071: Speech Patterns

    1071. Speech Patterns (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Peo ...

  2. 【算法笔记】A1071 Speech Patterns

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  3. PAT 1071 Speech Patterns[一般]

    1071 Speech Patterns (25 分) People often have a preference among synonyms of the same word. For exam ...

  4. PAT 甲级 1071 Speech Patterns (25 分)(map)

    1071 Speech Patterns (25 分)   People often have a preference among synonyms of the same word. For ex ...

  5. 1071 Speech Patterns——PAT甲级真题

    1071 Speech Patterns People often have a preference among synonyms of the same word. For example, so ...

  6. 1071. Speech Patterns (25)

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

  7. Speech Patterns (string)

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

  8. A1071. Speech Patterns

    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. 用Emacs编写mybatis

    用Emacs编写mybatis */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} ...

  2. k3 cloud中列表字段汇总类型中设置了汇总以后没有显示出汇总值

    处理方法,需要bos中的分组列信息中设置求和: 选择对应字段将其从左侧添加到右侧 方法二: 直接针对[价税合计]字段的列表汇总类型进行设置,步骤如下图所示

  3. 4.ireport基本使用

    转自:https://wenku.baidu.com/view/104156f9770bf78a65295462.html 第一部分,下载与安装 Ireport官网:http:// jasperfor ...

  4. R语言中的数据分析函数

    数学类函数 在求有缺失值的子集的最大值时候,需要先用na.re=TRUE去掉缺失值. 求几个特定百分位数 round(x,n) n表示保留的小数点位数 分布类函数 rnorm,密度高的数字,生成概率就 ...

  5. jieba库的使用

    jieba库的使用 jeiba库是一款很优秀的用于中文分词的第三方库,它通过一个汉词词典来确定汉字之间的关联概率,将概率较大的组成分词. 精准模式 把文本精准的分割开来,不存在冗余单词. jieba. ...

  6. EAN13条码的校验位的Excel算法

    校验位原公式: 单元格=10-RIGHT(SUM(MID($B3,{1;2;3;4;5;6;7;8;9;10;11;12},1)*{1;3;1;3;1;3;1;3;1;3;1;3})) 简化公式: 单 ...

  7. squid代理与缓存(下)

    squid代理与缓存(下) 6. squid代理模式案例 6.1 squid传统正向代理生产使用案例 6.1.1 squid传统正向代理两种方案 (1)普通代理服务器 作为代理服务器,这是SQUID的 ...

  8. 三 Bash Shell 结构

    Bash Shell 程序结构主要有 : 变量设定  内置命令 Shell 语法结构 函数 其他命令行程序构成 例子: [root@localhost ~]# vim test.sh #!/bin/b ...

  9. Linux 下源码安装ngnix

    版本说明: NGINX 版本1.12.0 pcre-8.40 zlib-1.2.11 openssl-1.1.0i   安装过程 # ./configure  --prefix=/usr/ngnix  ...

  10. 【转】SAP 各种记账凭证的更改&冲销

    一:更改 1,已经过帐的 FB02. 过完帐的允许更改的地方有限,只有凭证抬头文本,参照,分配,文本,原因代码等 2,预制凭证的更改. FBV2. 预制凭证可以更改的地方很多,只有凭证编码+公司代码+ ...