当前位置:网站首页>pta7-5新浪微博热门话题
pta7-5新浪微博热门话题
2022-06-09 16:40:00 【墨染枫】
新浪微博可以在发言中嵌入“话题”,即将发言中的话题文字写在一对“#”之间,就可以生成话题链接,点击链接可以看到有多少人在跟自己讨论相同或者相似的话题。新浪微博还会随时更新热门话题列表,并将最热门的话题放在醒目的位置推荐大家关注。
本题目要求实现一个简化的热门话题推荐功能,从大量英文(因为中文分词处理比较麻烦)微博中解析出话题,找出被最多条微博提到的话题。
输入格式:
输入说明:输入首先给出一个正整数N(≤10
5
),随后N行,每行给出一条英文微博,其长度不超过140个字符。任何包含在一对最近的#中的内容均被认为是一个话题,输入保证#成对出现。
输出格式:
第一行输出被最多条微博提到的话题,第二行输出其被提到的微博条数。如果这样的话题不唯一,则输出按字母序最小的话题,并在第三行输出And k more …,其中k是另外几条热门话题的条数。输入保证至少存在一条话题。
注意:两条话题被认为是相同的,如果在去掉所有非英文字母和数字的符号、并忽略大小写区别后,它们是相同的字符串;同时它们有完全相同的分词。输出时除首字母大写外,只保留小写英文字母和数字,并用一个空格分隔原文中的单词。
输入样例:
4
This is a #test of topic#.
Another #Test of topic.#
This is a #Hot# #Hot# topic
Another #hot!# #Hot# topic
输出样例:
Hot
2
And 1 more …
参考了某佬的做法%%%
传送门: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 = "";//存储中间结果
string s1="";//存储最后结果
s += ".";//每个字符后加一个结束标志
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]);//转化成小写
}
else if(flag){
//**保证存在话题才进行下一步操作**
if (word != " ")
s1 += word;
word = " ";//要给后面加入的前置空格
}
if (count == 2) {
//说明一个topic判断完毕
flag = 0;
count = 0;
st[x].insert(s1);
s1 = "";
word = "";
}
}
}
int main() {
int n;
cin >> n;
getchar();//这个一定要加…不然会读不完全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;//转化到大写
cout << str << endl;
cout << maxnum << endl;
break;
}
}
for (auto i : mp) {
if (i.second == maxnum)res++;
}
if (res > 1)
cout << "And " << res-1 << " more ...";
}
边栏推荐
猜你喜欢

科研实习 | 北京大学可视化与可视分析实验室招收暑期实习生和推免研究生

Penetration test - post penetration +lcx+frp
![[East China Normal University] information sharing for the first and second examinations](/img/f9/68b5b5ce21f4f851439fa061b477c9.jpg)
[East China Normal University] information sharing for the first and second examinations

天呐,嘉立创的单、双面板又又又降价了,同行还怎么玩儿?
老师送给学生的毕业赠言如何用云便签记录整理

【华东师范大学】初试复试考研资料分享
How to use cloud notes to record and sort out the graduation notes given by teachers to students

【華東師範大學】初試複試考研資料分享

JVM记一次CPU飙升

Use testeract to recognize text in pictures
随机推荐
R 安装/更新 package 报错:failed to lock directory ‘/home/anaconda3/envs/R4.1.2/lib/R/library’
【華東師範大學】初試複試考研資料分享
C#/VB. Net to generate directory bookmarks when word is converted to PDF
Small program startup performance optimization practice
Right click the project to add a reference, prompting that the call to the COM component returned an error HResult e_ FAIL
一款高颜值开源知识管理工具
Sbio | Chenyun group of Zhejiang University Review on the interaction mechanism between bacteria and fungi in agriculture
pyepics --Auto-saving: simple save/restore PVs
Use testeract to recognize text in pictures
Sphereex officially open source the database mesh oriented solution pisanix
『忘了再学』Shell基础 — 28、AWK中条件表达式说明
SphereEx 正式开源面向 Database Mesh 的解决方案 Pisanix
leetcode:240. Search 2D matrix II
Check whether the specified IP exists in the IP address Library
如何训练你的准确率?
How to solve warning: there was an error checking the latest version of pip
Pyepics array -- 4
The applet modifies the data of the previous page
ue4 bsp画刷中光源需要重建(x未构建对象)
关联数组&正则表达式