PTA 7-18 新浪微博热门话题
来源:互联网 发布:香港电视台直播软件 编辑:程序博客网 时间:2024/06/05 00:11
新浪微博可以在发言中嵌入“话题”,即将发言中的话题文字写在一对“#”之间,就可以生成话题链接,点击链接可以看到有多少人在跟自己讨论相同或者相似的话题。新浪微博还会随时更新热门话题列表,并将最热门的话题放在醒目的位置推荐大家关注。
本题目要求实现一个简化的热门话题推荐功能,从大量英文(因为中文分词处理比较麻烦)微博中解析出话题,找出被最多条微博提到的话题。
MAP瞎暴
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <string>#include <map>using namespace std;map<string, int> vis;map<string, int> cnt;map<string, int>::iterator it;bool judge(char c) { if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || '0' <= c && c <= '9' || c == ' ') return true; return false;}int main() { int n; scanf("%d", &n); getchar(); char str[1000]; string s; for (int i = 1; i <= n; i++) { gets(str); bool flag = false; vis.clear(); for (int i = 0; str[i]; i++) { if (str[i] == '#' && flag == false) { s.clear(); flag = true; } else if (str[i] != '#' && flag == true) { if (!judge(str[i])) str[i] = ' '; if ('A' <= str[i] && str[i] <= 'Z') str[i] += 32; int len = s.size(); if (len > 0 && str[i] == ' ' && s[len - 1] == ' ') continue; s.push_back(str[i]); } else if (str[i] == '#' && flag == true) { string ss; if (s[0] == ' ') for (int i = 1; i < s.size(); i++) ss.push_back(s[i]); else if (s[s.size() - 1] == ' ') for (int i = 0; i < s.size() - 1; i++) ss.push_back(s[i]); else ss = s; //cout << ss << endl; if (!vis[ss]) { vis[ss] = 1; cnt[ss]++; } flag = false; } } } int num = 0; int res = 0; string ans; for (it = cnt.begin(); it != cnt.end(); it++) { string x = it->first; int y = it->second; if (y > res) { num = 0; res = y; ans = x; } else if (y == res) num++; } ans[0] -= 32; cout << ans << endl << res << endl; if (num) cout << "And " << num << " more ..." << endl;}
阅读全文
0 0
- PTA 7-18 新浪微博热门话题
- PTA 7-18(查找) 新浪微博热门话题(30 分) 30分代码 (已更新)
- 《数据结构学习与实验指导》5-7:新浪微博热门话题
- Python 获取新浪微博的热门话题 (API)
- 5-46 新浪微博热门话题 (30分)
- 【python 新浪微博爬虫】python 爬取新浪微博24小时热门话题top500
- 新浪微博数据挖掘(python)本周人们在讨论的热门话题的提取
- 热门话题
- (python)热门话题的某些微博评论和转发数的抓取
- 高中生热门话题
- PTA 7-9 藏尾诗
- PTA
- PTA
- pta
- pta
- 新浪微博
- 新浪微博笔试
- 新浪微博架构
- PTA 7-15 航空公司VIP客户查询
- osmdroid API解读(九)
- TLPI-Chapter 11系统限制和选项
- CSS盒模型详解
- PTA 7-17 字符串关键字的散列映射
- PTA 7-18 新浪微博热门话题
- 【LeetCode】Validate Binary Search Tree 验证二叉查找树
- Leetcode 题解系列(六)
- 在PHP中使用AES加密算法加密数据及解密数据
- 7-19 寻找大富翁
- java常见异常
- 动态创建AppDomain一
- JTAG(SWD)的参考电压
- 机器学习常用算法总结(二)