• 计算机学院大学生程序设计竞赛(2015’12)Study Words


    Study Words

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


    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 <oldwords> and </oldwords> 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 <oldwords> and </oldwords> contain letters ('a'~'z','A'~'Z') only, separated by blank characters (' ',' ' or ' ').
    Between <article> and </article> 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 <oldwords> how aRe you </oldwords> <article> --How old are you? --Twenty. </article> <oldwords> google cn huluobo net i </oldwords> <article> 文章内容: 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"? </article>
     

    Sample Output
    old twenty firefox open s able and but computer days dropbox enjoy
     

    今天是2015年最后一个星期日,我用了好长好长好长时间做了这道题,测试答案不应该错,可是.........快哭了好伤心、

    不想再修改了。。。。就让它一直错吧!委屈下面的是正确的答案哦!


    #include<cstdio>
    #include<cstring>
    #include<map>
    #include<string>
    #include<algorithm>
    using namespace std;
    int T;
    char s[100+10];
    char r[100+10];
    map<string,int>m;
    struct dan
    {
        char s[100+10];
        int num;
    }d[1000000+10];
    int sum;
    int tot;
    bool cmp(const dan&a,const dan&b)
    {
        if(a.num==b.num) return strcmp(a.s,b.s)<0;
        return a.num>b.num;
    }
    
    //转小写
    void F()
    {
        for(int i=0;s[i];i++)
            if(s[i]>='A'&&s[i]<='Z')
                s[i]=s[i]-'A'+'a';
    }
    void work()
    {
        int len=strlen(s);
        tot=0;
        for(int i=0;i<=len;i++)
        {
            if(s[i]>='a'&&s[i]<='z') r[tot++]=s[i];
            else
            {
                r[tot]='';
                if(strlen(r)>0) m[r]=-1;
                tot=0;
            }
        }
    }
    void work2()
    {
        int len=strlen(s);
        tot=0;
        for(int i=0;i<=len;i++)
        {
            if(s[i]>='a'&&s[i]<='z') r[tot++]=s[i];
            else
            {
                r[tot]='';
                if(strlen(r)>0)
                {
                    if(m[r]!=-1)
                    {
                        if(m[r]==0) strcpy(d[sum++].s,r);
                        m[r]++;
                    }
                }
                tot=0;
            }
        }
    }
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            int flag=0;
            m.clear();
            sum=0;
            while(1)
            {
                scanf("%s",s);
                if(strcmp(s,"<oldwords>")==0) {flag=1;continue;}
                if(strcmp(s,"</oldwords>")==0) {flag=2;continue;}
                if(strcmp(s,"<article>")==0) {flag=3;continue;}
                if(strcmp(s,"</article>")==0) break;
                if(flag==1)
                {
                    F();
                    work();
                }
                if(flag==3)
                {
                    F();
                    work2();
                }
            }
            for(int i=0;i<sum;i++) d[i].num=m[d[i].s];
            sort(d,d+sum,cmp);
            for(int i=0;i<min(10,sum);i++) printf("%s
    ",d[i].s);
            printf("
    ");
        }
        return 0;
    }
    


    @执念  "@☆但求“❤”安★下次我们做的一定会更好。。。。吐舌头

    为什么这次的题目是英文的。。。。QAQ...哭

    ------------------- 这是千千的个人网站哦! https://www.dreamwings.cn -------------------
  • 相关阅读:
    安装 Java 开发工具包JDK(Windows版本)
    在sublime text 3中让.vue文件的内容变成彩色
    iOS之禁止所有输入法的表情
    iOS之UIButton扩大按钮的响应区域
    iOS之利用腾讯Bugly程序调试,测试代码bug、卡顿等情况
    iOS之在本地搭建IPv6环境测试你的app
    iOS之让UISearchBar搜索图标和placeholder靠左显示
    iOS之限制TextField的输入长度
    iOS之oc与html之间的交互(oc中调用js的方法)
    iOS之面试题:腾讯三次面试以及参考思路
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989693.html
Copyright © 2020-2023  润新知