UVA 12686 Trending Topic
Trending Topic
Time limit: 1.000 seconds
Imagine you are in the hiring process for a company whose principal activity is the analysis of information in the Web. One of the tests consists in writing a program for maintaining up to date a set of trending topics. You will be hired depending on the efficiency of your solution. They provide you with text from the most active blogs. The text is organised daily and you have to provide the sorted list of the N most frequent words during the last 7 days, when asked.
INPUT
Each input file contains one test case. The text corresponding to a day is delimited by tag <text>. Queries of top N words can appear between texts corresponding to two different days. A top N query appears as a tag like <top 10 />. In order to facilitate you the process of reading from input, the number always will be delimited by white spaces, as in the sample.
Notes:
• All words are composed only of lowercase letters of size at most 20.
• The maximum number of different words that can appear is 20000.
• The maximum number of words per day is 20000.
• Words of length less than four characters are considered of no interest.
• The number of days will be at most 1000.
• 1 ≤ N ≤ 20
OUTPUT
The list of N most frequent words during the last 7 days must be shown given a query. Words must appear in decreasing order of frequency and in alphabetical order when equal frequency. There must be shown all words whose counter of appearances is equal to the word at position N. Even if the amount of words to be shown exceeds N.
SAMPLE INPUT
<text> imagine you are in the hiring process of a company whose main business is analyzing the information that appears in the web </text>
<text> a simple test consists in writing a program for maintaining up to date a set of trending topics </text>
<text> you will be hired depending on the efficiency of your solution </text>
<top 5 />
<text> they provide you with a file containing the text corresponding to a highly active blog </text>
<text> the text is organized daily and you have to provide the sorted list of the n most frequent words during last week when asked </text>
<text> each input file contains one test case the text corresponding to a day is delimited by tag text </text>
<text> the query of top n words can appear between texts corresponding to two different days </text>
<top 3 />
<text> blah blah blah blah blah blah blah blah blah please please please </text>
<top 3 />
SAMPLE OUTPUT
<top 5>
analyzing 1
appears 1
business 1
company 1
consists 1
date 1
depending 1
efficiency 1
hired 1
hiring 1
imagine 1
information 1
main 1
maintaining 1
process 1
program 1
simple 1
solution 1
test 1
that 1
topics 1
trending 1
whose 1
will 1
writing 1
your 1
</top>
<top 3>
text 4
corresponding 3
file 2
provide 2
test 2
words 2
</top>
<top 3>
blah 9
text 4
corresponding 3
please 3
</top>
解题:极其蛋疼狗血的破题目。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
struct cao{
string word;
int cnt;
cao(string x = "*",int y = ){
word = x;
cnt = y;
}
};
map<string,int>mp;
string tmp;
vector<string>v[];
cao nima[];
bool cmp(const cao &x,const cao &y){
if(x.cnt == y.cnt) return x.word < y.word;
return x.cnt > y.cnt;
}
int main() {
mp.clear();
int n = ,i,j,ask,tot;
while(cin>>tmp){
if(tmp == "<text>"){
j = n%;
for(i = ; i < v[j].size(); i++) mp[v[j][i]]--;
v[j].clear();
while(cin>>tmp){
if(tmp == "</text>") break;
if(tmp.length() >= ){
mp[tmp]++;
v[j].push_back(tmp);
}
}
n++;
}else{
cin>>ask>>tmp;
tot = ;
for(map<string,int>::iterator it = mp.begin();it != mp.end(); it++)
nima[tot++] = cao(it->first,it->second);
sort(nima,nima+tot,cmp);
printf("<top %d>\n",ask);
for(i = ,j = ; i < ask; i++)
printf("%s %d\n",nima[i].word.c_str(),nima[i].cnt);
for(j = i,i--; j < tot && nima[j].cnt == nima[i].cnt; j++)
printf("%s %d\n",nima[j].word.c_str(),nima[j].cnt);
puts("</top>");
}
}
return ;
}
UVA 12686 Trending Topic的更多相关文章
- SWERC13 Trending Topic
map暴力. .. Imagine you are in the hiring process for a company whose principal activity is the analys ...
- USER STORIES AND USE CASES - DON’T USE BOTH
We’re in Orlando for a working session as part of the Core Team building BABOK V3 and over dinner th ...
- [转载]Three Trending Computer Vision Research Areas, 从CVPR看接下来几年的CV的发展趋势
As I walked through the large poster-filled hall at CVPR 2013, I asked myself, “Quo vadis Computer V ...
- UVA 607 二十二 Scheduling Lectures
Scheduling Lectures Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- UVa 10006 - Carmichael Numbers
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some ...
- Kafka 如何读取offset topic内容 (__consumer_offsets)
众所周知,由于Zookeeper并不适合大批量的频繁写入操作,新版Kafka已推荐将consumer的位移信息保存在Kafka内部的topic中,即__consumer_offsets topic,并 ...
- Kafka如何创建topic?
Kafka创建topic命令很简单,一条命令足矣:bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-facto ...
- Kafka0.8.2.1删除topic逻辑
前提条件: 在启动broker时候开启删除topic的开关,即在server.properties中添加: delete.topic.enable=true 命令: bin/kafka-topics ...
- [bigdata] kafka基本命令 -- 迁移topic partition到指定的broker
版本 0.9.2 创建topic bin/kafka-topics.sh --create --topic topic_name --partition 6 --replication-factor ...
随机推荐
- PCB 漏加阻抗条的臆想(转)
阻抗条,我对你是有感情的,这你一定要相信我! 否则,不会在之前的每一次拼板,都不忘拥你入Panel之怀. 自做CAM开始,已记不清我们曾有多少次不期而遇, 我们一同迎接朝阳,送走晚霞,凝望窗外如洗的月 ...
- E20180121
signature n. 签名; 署名; 识别标志,鲜明特征; [医] 药的用法说明;
- ionic安卓打包apk--安卓签名
上周项目上线,在网上看了看打包的博客,感觉不是很清晰我自己来总结下 首先,我们在项目的根目录下 build android apk 的时候执行的命令一定要是 ionic build android - ...
- python之Beautiflusoup操作
from bs4 import BeautifulSoupimport requestsimport os ######对风景进行爬出操作r = requests.get("http://6 ...
- Akka源码分析-Cluster-Distributed Publish Subscribe in Cluster
在ClusterClient源码分析中,我们知道,他是依托于“Distributed Publish Subscribe in Cluster”来实现消息的转发的,那本文就来分析一下Pub/Sub是如 ...
- ADSI和其他内容
ADSI (Active Directory Services Interface)是Microsoft推出的一项技术,它统一了许多底层服务的编程接口,程序员可以使用一致的对象技术来访问这些底层服务. ...
- msxml3.dll 错误 '800c0005' 系统错误: -2146697211。
asp网站 因为这个问题,困扰自己好多次,还重装过两次服务器系统,非常的麻烦,这次终于找到了问题所在,记录下来,方便以后查看. 服务器症状: 1.服务器上的IE浏览器不能访问外网: 2.set htt ...
- Java&Xml教程(八)使用JDOM将Java对象转换为XML
在前面的教程中我们学习了如何使用JDOM解析和修改XML文件内容,本节介绍如何将Java对象转换为XML数据并生成文件. JDOM的Document类提供了便捷的方法创建元素和属性,XMLOutput ...
- python学习笔记(7)——集合(set)
关键词#1.定义:无序不重复元素集, 基本功能包括关系测试和消除重复元素. 2.关键词:类似dict.只有key无value.常用于集合类数学运算. 3.创建 s=set() #入参可以是list.t ...
- 第五届蓝桥杯校内选拔第七题_(树型dp)
G将军有一支训练有素的军队,这个军队除开G将军外,每名士兵都有一个直接上级(可能是其他士兵,也可能是G将军).现在G将军将接受一个特别的任务,需要派遣一部分士兵(至少一个)组成一个敢死队,为了增加敢死 ...