浙江大学PAT_甲级_1071. Speech Patterns (25)

PAT甲级 1071 Speech Patterns (25 分) 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 exampl 阅读详情

题目链接:点击打开链接

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
我的C++代码:

#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	string sentence;
	getline(cin, sentence);//输入一句话
	map<string, int> word_frequency;//单个单词出现的次数
	string word;//单词
	int i = 0;
	vector<string>vec_word;//存储单词的vector
	int max_frequency = 0;//最大出现次数
	string most_commonly_word;//出现次数最多的单词
	for (i = 0; i <sentence.length(); i++)//把一句话分解成单词组成的vector
	{
		word= "";
		while (isalnum(sentence[i]))//字符是数字或字母
		{
			if (isupper(sentence[i]))//大写转小写
				sentence[i] = tolower(sentence[i]);
			word += sentence[i];//得到单个的单词
			i++;
		}
		if (word!= "")
			vec_word.push_back(word);//把单词放进vector
	}
	for (int i = 0; i<vec_word.size(); i++)//把单词放进map
	{
		word_frequency [ vec_word[i] ]++;//记录每个单词的出现次数
		if (max_frequency <word_frequency [vec_word[i]] )//查找出现次数最多的单词
		{
			max_frequency = word_frequency [vec_word[i]];
			most_commonly_word = vec_word [i];
		}
	}
	cout << most_commonly_word << " " << max_frequency;//输出最常见的单词,和出现次数
	//system("pause");
	return 0;
}


SAP UI5 主题设置全解析:从启动参数到运行时切换、跨域白名单与事件监听 SAP UI5主题体系深度解析:从配置到切换的完整指南 摘要:SAP UI5主题机制远不止CSS换肤,其工程化实践涵盖启动配置、运行时API切换、跨库路径映射及安全管控等关键环节。通过bootstrap标签或URL参数设置初始主题,运行时可用Theming.setTheme无刷新切换。自定义主题需配置theme-roots路径,跨域加载需声明sap-allowed-theme-origins白名单。主题切换完成后会触发applied事件,适合执行视觉同步操作。该体系支持多品牌适配、集中式主题管理,在Fior 阅读详情

相关推荐

智能车八邻域图像算法

智能车八邻域图像算法

技术缝合怪的博客 4万+

PAT 1071 Speech Patterns

目录 题目 题目阅读 Input Specification: Output Specification: Sample Input: Sample Output: 解题思路 代码 题目 1071 Speech Patterns 题目阅读 People often have a preference(偏爱) among synonyms(同义词) of the sa...

Do Better 332

OpenClaw 在 Windows 环境下的完整安装、配置和部署指南

介绍Windows环境下OpenClaw的完整安装,配置和部署的全流程

hxbao的专栏 1497

PAT 1071 Speech Patterns python解法

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

qq_36936510的博客 415

AI Agent在智能投研中的实战:多智能体信息整合与策略生成

那么,什么是AI Agent?简单来说,AI Agent是一种能够感知环境、做出决策并采取行动的自主系统。自主性:能够在没有人类直接干预的情况下运行,对自己的行为和内部状态有一定的控制权。反应性:能够感知环境的变化,并及时做出反应。主动性:不仅能够对环境变化做出反应,还能够主动地设定目标并采取行动实现这些目标。社会性:能够与其他Agent(包括人类和人工智能)进行交互、协作和竞争。它们可以全天候不间断地监控和处理海量信息,大大提升信息处理能力;

AI大模型应用之禅 212

深入解析XTEA加密算法的核心机制与优化策略

本文深入解析XTEA加密算法的核心机制与优化策略,详细介绍了XTEA在嵌入式系统和资源受限环境中的优势,包括其高效的加解密速度和低资源消耗。文章还探讨了XTEA的轮函数设计、关键参数优化策略以及实战应用中的性能对比,为开发者提供了安全增强方案和优化技巧。

k8l9m0n的博客 251

PAT甲级1071 Speech Patterns

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

weixin_44535077的博客 222

lammps案例:扭转

扭转有两种方式,一是固定一端旋转另外一端,二是两端沿相反的方向旋转。案例为两侧旋转方式,扭转后的效果如图所示。

lammps_jiayou的博客 1204

PAT甲级真题1071 Speech Patterns 【 字符串处理 】题解

目录1.题目2.代码 1.题目 不同 的人对描述同一种事物的同义词的偏爱程度可能不同。 例如,在说警察时,有人喜欢用 the police,有人喜欢用 the cops。 分析说话方式有助于确定说话者的身份,这在验证诸如和你线上聊天的是否是同一个人十分有用。 现在,给定一段从某人讲话中提取的文字,你能确定他的最常用词吗? 输入格式 输入共一行,包含一个字符串,以回车符 \n 终止。 输出格式 共一行,输出最常用词以及其出现次数。 如果常用词有多个,则输出字典序最小的那个单词。 注意,单词在输出时,必须全部小

林深不见鹿 的博客 474

Android Audio基础——系统服务(二)

AudioService 继承自 IAudioService.Stub。IAudioService.Stub 类很明显是通过 IAudioService.aidl 自动生成的。AudioService 位于 Binder Native 端。AudioManager 拥有 AudioService 的 Binder Proxy 端,是 AudioService 在客户端的一个代理。几乎所有客户端对 AudioManager 进行的请求,最终都会交由 AudioService 实现。

小旭的专栏 2094

USB 基础学习:USB 电气信号介绍

USB电气信号技术解析 USB通信的核心是差分信号传输技术,通过D+和D-两根线传输相位相反的电压信号实现数据通信。USB信号系统包含三类关键信号:差分数据信号(抗干扰性强)、单端状态信号(用于设备识别)和电源信号(提供5V供电)。USB2.0采用400mV电压摆幅和NRZI编码,支持低速(1.5Mbps)至高速(480Mbps)传输;USB3.0则新增专用差分对,数据速率可达20Gbps。物理层通过上拉/下拉电阻检测设备连接,高速模式需特殊握手协议。抗干扰设计的关键在于保持差分线等长、阻抗匹配和使用共模扼

浩瀚之水的专栏 1795

PAT甲级 P1071 Speech Patterns(25分)题目详解,附AC代码

PAT 甲级 1071 Speech Patterns(25分) 1071 Speech Patterns (25分) 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 pa.

qq_45528761的博客 202

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

【PAT甲级A1071】Speech Patterns (25分)(c++)

1071 Speech Patterns (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB 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

小庄同学的博客 133

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

PAT甲级 1071 Speech Patterns

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 146

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

浙江大学PAT_甲级_1094. The Largest Generation (25)

题目链接:点击打开链接 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest po

~~(v_v)~~ 1240

PAT_甲级_1001. A+B Format (20)

1001. A+B Format (20)   Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input...

~~(v_v)~~ 1172

浙江大学PAT_甲级_1005.1005. Spell It Right (20)

c++实现

~~(v_v)~~ 991

浙江大学PAT_甲级_1032. Sharing (25)

题目地址:点击打开链接 To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suf

~~(v_v)~~ 778

PAT_甲级_1029. Median (25)

题目链接:点击打开链接   Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16...

~~(v_v)~~ 746

浙江大学PAT_甲级_1035. Password (20)

C++

~~(v_v)~~ 736

浙江大学PAT_甲级_1081. Rational Sum (20)

题目链接:点击打开链接 Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum. Input Specification: Each input file contains one test case. Each case sta

~~(v_v)~~ 730

浙江大学PAT_甲级_1023. Have Fun with Numbers (20)

python

~~(v_v)~~ 721

浙江大学PAT_甲级_1036. Boys vs Girls (25)

C++

~~(v_v)~~ 715

PAT_甲级_1065. A+B and C (64bit) (20)

题目链接:点击打开链接   Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B &gt; C. Input Specification: The first line of the input gives the positive number of test cases,...

~~(v_v)~~ 706

浙江大学PAT_甲级_1070. Mooncake (25)

题目链接:点击打开链接 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the regio

~~(v_v)~~ 687

浙江大学PAT_甲级_1028. List Sorting (25)

C++

~~(v_v)~~ 678
上一篇: 浙江大学PAT_甲级_1059. Prime Factors (25)
下一篇: MOOC数据结构-01-复杂度1 最大子列和问题 (20分)
pythontojava
博客等级 码龄12年 84粉丝 140原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址