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

#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]=‘\0‘;
            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]=‘\0‘;
            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\n",d[i].s);
        printf("\n");
    }
    return 0;
}
时间: 2024-10-03 13:22:45

计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words的相关文章

hdu 计算机学院大学生程序设计竞赛(2015’11)

搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5134    Accepted Submission(s): 1288 Problem Description 小明现在是人见人爱,花见花开的高富帅,整天沉浸在美女环绕的笙歌妙舞当中.但是人们有所不知,春风得意的小明也曾有着一段艰苦的奋斗史. 那时的小明还没剪去长发,没有信用卡没有她

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

题意: 输入一篇文章,输出出现最多的10个单词 不包括old里的已有单词 出现次数相同按字典序大小 简单模拟,map记录个数 没有什么坑点 然后sort一下 用string 可以直接比较字典序大小 #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorithm> #include<map> #include<mat

HDU计算机学院大学生程序设计竞赛(2015’12)Happy Value

Happy Value Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1453    Accepted Submission(s): 428 Problem Description In an apartment, there are N residents. The Internet Service Provider (ISP) wa

HDU计算机学院大学生程序设计竞赛(2015’12)The Country List

The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2598    Accepted Submission(s): 615 Problem Description As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable

计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

Problem Description There is a collector who own many valuable jewels. He has a problem about how to store them. There are M special boxes. Each box has a value. And each of the N jewels has a value too. The collector wants to store every jewel in on

计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

#include<cstdio> #include<algorithm> using namespace std; using namespace std; const int maxn=100000+10; int a[maxn],b[maxn]; int main() { int n,m; while(scanf("%d %d",&n,&m)!=EOF) { for(int i=1; i<=n; i++) scanf("%d&

计算机学院大学生程序设计竞赛(2015’12) 1002 Polygon

#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct Point { double x; double y; } p[1001], px[10001]; int n; double eps=1e-8; int cmp(Point a, Point b) { if(ab

计算机学院大学生程序设计竞赛(2015’12) 1001 The Country List

#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<vector> #include<map> #include<algorithm> using namespace std; char s[100+10][20+10]; int n; map<string ,int>m; int main() { while

计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations

#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=120; long long X,K; long long basex[maxn]; long long basek[maxn]; int totx,totk; int main() { int T; scanf("%d",&a