HDU電腦學院大學生程式設計競賽(2015’12)1008 Study Words

來源:互聯網
上載者:User

標籤:

題意:

輸入一篇文章,輸出出現最多的10個單詞

不包括old裡的已有單詞

出現次數相同按字典序大小

 

簡單類比,map記錄個數

沒有什麼坑點

然後sort一下

用string 可以直接比較字典序大小

#include<cstdio>#include<cstring>#include<string>#include<iostream>#include<algorithm>#include<map>#include<math.h>using namespace std;char s[205],m[]={"</article>"};struct node{    string a;    int v;}p[150005];bool cmp(node a,node b){    if(a.v==b.v) return a.a<b.a;    return a.v>b.v;}int main(){    int i,j,n;    int T;    scanf("%d",&T);    while(T--)    {        scanf("%s",s);        map<string,int> f;        while(scanf("%s",s))        {            int l=strlen(s);            for(i=0;i<l;i++)            {                if(s[i]>=‘A‘&&s[i]<=‘Z‘) s[i]+=32;            }            if(s[0]==‘<‘) break;f[s]=-1;        }        scanf("%s",s);        int cnt=0;        while(scanf("%s",s))        {            int l=strlen(s);            if(l==10)            {                for(i=0;i<l;i++)                {                    if(s[i]==m[i]) continue;                    break;                }                if(i==10) break;            }            string tp="";            for(i=0;i<l;i++)            {                if(s[i]>=‘A‘&&s[i]<=‘Z‘) s[i]+=32;                if(s[i]>=‘a‘&&s[i]<=‘z‘)                    tp+=s[i];                else                {                    if(tp=="") continue;                    if(f[tp]==0)                    {                        f[tp]=++cnt;                        p[cnt].a=tp;                        p[cnt].v=1;                    }                    else                        p[f[tp]].v++;                    tp="";                }            }            if(tp=="") continue;                    if(f[tp]==0)                    {                        f[tp]=++cnt;                        p[cnt].a=tp;                        p[cnt].v=1;                    }                    else                        p[f[tp]].v++;        }        sort(p+1,p+1+cnt,cmp);        for(i=1;i<=10&&i<=cnt;i++) cout<<p[i].a<<endl;        cout<<endl;    }    return 0;}

 

  

HDU電腦學院大學生程式設計競賽(2015’12)1008 Study Words

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.