2015‘12杭电校赛1008 Study Words(map,vector瞎搞)

题解:

有中文输入吓了一跳,不过强行各种STL开搞!

代码

#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <bitset>
#define MAX 100000
#define LL long long
using namespace std;
int cas=1,T,n;
char word[110];
int main()
{
   // freopen("in","r",stdin);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%*s");
        set<string>old;
        map<string,int>news;
        old.clear();
        news.clear();
        while(scanf("%s",word)&&word[0]!='<')
        {
            for(int i=0;word[i];i++) word[i]=tolower(word[i]);
// puts(word);
            old.insert(word);
        }
        scanf("%*s");
        char c,flag=0,i=0;
        while(c=getchar())
        {
            if(c=='<') break;
            if(isalpha(c))
            {
                c=tolower(c);
                word[i++]=c;
                flag=1;
            }
            else if(flag)
            {
                word[i]=0;
// puts(word);
                i=flag=0;
                if(old.count(word)) continue;
                news[word]++;
            }
        }
        scanf("%*s");
        for(int i=0;i<10&&!news.empty();i++)
        {
            string maxs;
            int maxt=0;
            for(map<string,int>::iterator it=news.begin();it!=news.end();it++)
            {
                if(maxt<it->second||maxt==it->second&&maxs > it->first)
                {
                    maxt=it->second;
                    maxs=it->first;
                }
            }
            cout<<maxs<<endl;
            news.erase(maxs);
        }
        puts("");
    }
    //printf("time=%.3lf\n",(double)clock()/CLOCKS_PER_SEC);
    return 0;
}

题目

Study Words

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 267 Accepted Submission(s): 97

Problem Description

Learning English is not easy, vocabulary troubles me a lot.
One day an idea came up to me: I download an article every day, choose the 10 most popular new words to study.
A word’s popularity is calculated by the number of its occurrences.
Sometimes two or more words have the same occurrences, and then the word with a smaller lexicographic has a higher popularity.

Input

T in the first line is case number.
Each case has two parts.
< oldwords >

< /oldwords >
< article >

< /article >
Between and are some old words (no more than 10000) I have already learned, that is, I don’t need to learn them any more.
Words between and contain letters (‘a’~’z’,’A’~’Z’) only, separated by blank characters (’ ‘,’\n’ or ‘\t’).
Between

and is an article (contains fewer than 1000000 characters).
Only continuous letters (‘a’~’z’,’A’~’Z’) make up a word. Thus words like “don’t” are regarded as two words “don” and “t”, that’s OK.
Treat the uppercase as lowercase, so “Thanks” equals to “thanks”. No words will be longer than 100.
As the article is downloaded from the internet, it may contain some Chinese words, which I don’t need to study.

Output

For each case, output the top 10 new words I should study, one in a line.
If there are fewer than 10 new words, output all of them.
Output a blank line after each case.

Sample Input

2

how aRe you


–How old are you?
–Twenty.


google cn huluobo net i


文章内容:
I love google,dropbox,firefox very much.
Everyday I open my computer , open firefox , and enjoy surfing on the inter-
net.
But these days it’s strange that searching “huluobo” is unavail-
able.
What’s wrong with “huluobo”?

Sample Output

old
twenty

firefox
open
s
able
and
but
computer
days
dropbox
enjoy

你可能感兴趣的:(2015‘12杭电校赛1008 Study Words(map,vector瞎搞))