当前位置:网站首页>Pta7-5 Sina Weibo hot topics
Pta7-5 Sina Weibo hot topics
2022-06-10 00:19:00 【Ink dyed maple】
Sina Weibo can embed “ topic of conversation ”, The topic of the speech will be written in a pair of “#” Between , You can generate topic links , Click the link to see how many people are discussing the same or similar topics with themselves . Sina Weibo will also update the list of hot topics at any time , And put the hottest topics in an eye-catching position and recommend everyone to pay attention to .
This topic requires a simplified hot topic recommendation function , From a large number of English ( Because Chinese word segmentation is troublesome ) Analyze the topic in the microblog , Find the topics mentioned by the most microblogs .
Input format :
Enter description : Input first gives a positive integer N(≤10
5
), And then N That's ok , Each line gives an English microblog , Its length does not exceed 140 Characters . Anything contained in a pair of recent # The content in is considered to be a topic , Input guarantee # Pairs appear .
Output format :
The first line outputs the topics mentioned by the most microblogs , The second line outputs the number of microblogs mentioned . If such a topic is not unique , Then the topic with the smallest alphabetical order is output , And output... On the third line And k more …, among k Is the number of other hot topics . The input ensures that there is at least one topic .
Be careful : The two topics are considered to be the same , If you remove all symbols of non English letters and numbers 、 And ignore the case distinction , They are the same string ; At the same time, they have exactly the same participle . Except for the first letter of output , Keep only lowercase English letters and numbers , Separate the words in the original text with a space .
sample input :
4
This is a #test of topic#.
Another #Test of topic.#
This is a #Hot# #Hot# topic
Another #hot!# #Hot# topic
sample output :
Hot
2
And 1 more …
It refers to the practice of a guy %%%
Portal :https://blog.csdn.net/qq_48508278/article/details/119637352
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
int a[N];
map<string, int>mp;
set<string>st[N];
void duru(string s,int x) {
int flag = 0;
int count = 0;
string word = "";// Store intermediate results
string s1="";// Store the final result
s += ".";// Add an end sign after each character
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') {
count++;
flag = 1;
if (i < s.size() - 1)
i++;
}
if(isalpha(s[i])&&flag||isdigit(s[i])&&flag){
if (isdigit(s[i]))
word += s[i];
if (isalpha(s[i]))
word += tolower(s[i]);// Convert to lowercase
}
else if(flag){
//** Ensure that there is a topic before proceeding to the next step **
if (word != " ")
s1 += word;
word = " ";// The leading space to be added later
}
if (count == 2) {
// Explain a topic Judgment complete
flag = 0;
count = 0;
st[x].insert(s1);
s1 = "";
word = "";
}
}
}
int main() {
int n;
cin >> n;
getchar();// This must be added with … Otherwise you will not read it completely orz
for (int i = 0; i < n; i++) {
char s[150];
cin.getline(s,150 );
duru(s, i);
for (auto it:st[i]) {
/* cout << it << endl;*/
mp[it] += 1;
}
/* puts("");*/
}
int maxnum = 0;
for (auto it : mp) {
if (it.second > maxnum)maxnum = it.second;
}
int res = 0;
for (map<string, int>::iterator it = mp.begin(); it != mp.end();it++) {
if (it->second == maxnum) {
//res++;
string str = it->first;
str[0] = str[0] - 32;// Convert to uppercase
cout << str << endl;
cout << maxnum << endl;
break;
}
}
for (auto i : mp) {
if (i.second == maxnum)res++;
}
if (res > 1)
cout << "And " << res-1 << " more ...";
}
边栏推荐
- AI chief architect 5-aica-wenxin NLP large model technology and Application
- numpy基础操作
- Game installation, downloading and updating no unveils the mystery of future games
- sparksql源码系列 | 一文搞懂Distribution源码体系(spark3.2)
- « Lorsque vous n'êtes plus programmeur, beaucoup de choses échappent au contrôle » - conversation avec Suse CTO, la plus grande entreprise open source indépendante au monde
- Is Huishang futures regular? Is it safe to open an account?
- 请教一个问题,pg有类似mysql server_id一样的实例唯一标识么?
- C # practical skills: package the icon into DLL and read it
- Retrofit2.0 method summary of adding header
- 2022-06-10日报: 华为十大发明公布:高效加法网络、多目标博弈智能驾驶获奖
猜你喜欢

Py6s configuration tutorial (win10 × 64)

辐射亮度与表观反射率的转换

ArcMap resolving geometric errors

思维导图----3、SQL注入漏洞

“當你不再是程序員,很多事會脫離掌控”—— 對話全球最大獨立開源公司SUSE CTO

I've taken it. The MySQL table has 500W rows. Is there anyone who doesn't partition?

With the advent of the digital era, 360 has joined hands with the dark horse of entrepreneurship to help small and medium-sized enterprises seize the key future

Do your filial duty to make an old people's fall prevention alarm system for your family

哨兵3(Sentinel-3)数据简介

JVM 讲解
随机推荐
View the installable version number of the wheel on this computer
Go技术日报(2022-06-08)——聊聊索引失效的10种场景,太坑了
蓝桥杯_分割立方体_组合数学_加法原理
How about opening an account at CICC securities? Is it safe? Account opening
打开xlsx文件时自动打开personal.xlsb表格文件
929. 独特的电子邮件地址
The essence and soul of message queue
Virtual machine environment configuration record 1
C # WPF realizes dynamic increase and decrease of tab page
If (obj! = null) is not required
Is it necessary for a bank to establish a data center? You will understand after reading it
Sentinel-3 data introduction
Q-learning
Py6S配置教程(win10 ×64)
Composition and configuration of Beidou clock synchronization system in power system
opencv体系结构
C# WPF布局控件LayoutControl介绍
模拟退火-n皇后问题
SIGIR 2022 | 港大、武大提出KGCL:基于知识图谱对比学习的推荐系统
I've taken it. The MySQL table has 500W rows. Is there anyone who doesn't partition?