SWERC13 Trending Topic, swerc13trending

Source: Internet
Author: User

SWERC13 Trending Topic, swerc13trending


Map brute force...


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
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
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
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
Please
</Text>
<Top 3/>
2
Problem IProblem I
Trending Topic
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 <algorithm>#include <string>#include <map>#include <vector>using namespace std;typedef pair<int,int> pII;map<string,int> Hash;vector<int> dy[11];string rHash[20200];int day_sum[11][20200];char cache[30];int now=9,pre=0,id=1;int arr[20020],na;string rss[20020];bool vis[20020];void DEBUG(int x){    int sz=dy[x].size();    for(int i=0;i<sz;i++)    {        cout<<"ID: "<<dy[x][i]<<" : "<<rHash[dy[x][i]]<<endl;        cout<<"sum: "<<day_sum[x][dy[x][i]]<<endl;    }}struct RSP{    int times;    string word;}rsp[20020];bool cmpRSP(RSP a,RSP b){    if(a.times!=b.times)        return a.times>b.times;    else        return a.word<b.word;}void get_top(int now,int k){    int sz=dy[now].size();    na=0;    int _7dayago=(now+3)%10;    memset(vis,false,sizeof(vis));    for(int i=0;i<sz;i++)    {        if(vis[dy[now][i]]==false)        {            arr[na++]=day_sum[now][dy[now][i]]-day_sum[_7dayago][dy[now][i]];            vis[dy[now][i]]=true;        }    }    sort(arr,arr+na);    int sig=arr[max(0,na-k)];    int rn=0;    memset(vis,false,sizeof(vis));    for(int i=0;i<sz;i++)    {        int times=day_sum[now][dy[now][i]]-day_sum[_7dayago][dy[now][i]];        if(times >= sig &&vis[dy[now][i]]==false)        {            rsp[rn++]=(RSP){times,rHash[dy[now][i]]};            vis[dy[now][i]]=true;        }    }    sort(rsp,rsp+rn,cmpRSP);    printf("<top %d>\n",k);    for(int i=0;i<rn;i++)    {        cout<<rsp[i].word<<" "<<rsp[i].times<<endl;    }    printf("</top>\n");}int main(){    while(scanf("%s",cache)!=EOF)    {        if(strcmp(cache,"<text>")==0)        {            ///read cache            pre=now;            now=(now+1)%10;            dy[now]=dy[pre];            memcpy(day_sum[now],day_sum[pre],sizeof(day_sum[0]));            ///7 day ago    ....            while(scanf("%s",cache))            {                if(cache[0]=='<') break;                if(strlen(cache)<4) continue;                string word=cache;                if(Hash[word]==0)                {                    rHash[id]=word;                    Hash[word]=id++;                }                int ID=Hash[word];                if(day_sum[pre][ID]==0)                    dy[now].push_back(ID);                day_sum[now][ID]++;            }        }        else if(strcmp(cache,"<top")==0)        {            int top;            scanf("%d",&top); scanf("%s",cache);            get_top(now,top);        }    }    return 0;}



Two hundred points for English help (not translation)> <

Kony has recently become famous through a viral video on YouTube. the video vividly describes what crimes Kony has committed in the past few years. he is a dictator in Uganda who enslaves children to be his soldiers. the local authorities cannot stop Kony and the U. s. government is not doing much either. the video attempts to get the word out to the people, to make the government be aware of this growing problem unfolding in Africa. it is a truly emotional video that have affected into people. eager viewers have donated money to the Invisible Children fund hoping to help out. the truth is, the video took policyears to create and the current situation in Uganda is much different than what is being described. kony's power has actually gone down by a huge amount, most of his enslaved children have been freed and he is in hiding. in my opinion the video created by Invisible Children is a publicity stunt to try to get more people to donate money to them. where if you look at their budget distribution, you can see that most of the money are spent toward campaigning and very little is actually being used to help out the people in Africa. in fact, the CEO of Invisible Children was recently arrested for public indecency and drug use. this whole ordeal about "Kony 2012" has taught us a lesson. do not believe in everything you see, make sure to do your own research before voicing your opinion or perform actions.

These should be enough.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.