poj1677-Girls' Day

模拟题poj-1677-Girls' Day

Description

On Girls' Day (Haven't heard about it? Well, you may ask the author for details...), we boys get together with girls in the class. On the occasion, every boy will make a wish for girls. Boys want to know about girls' responses to their wishes. 

If a wish contains one or more girls' names, it is considered to be talking to them specifically. Otherwise it is talking to all the girls. A wish can simultaneously talk to several girls of course. 

A girl would say 'oh' if the wish contains at most 9 words. 
A girl would say 'xixi' if the wish contains at least 10 words and she hears the word 'beautiful', 'pretty' or 'lovely'. 
A girl would say 'hehe' if the wish contains at least 10 words and she doesn't hear such words mentioned above. 

It is confirmed that a wish will not contain all the girls? name. 

Input

The first line of the input contains two integers g and w (1 <= g <= 5, 1 <= w <= 30), the number of girls and the number of wishes respectively. The next g lines each contain a word in lowercase, representing the name of a girl. Then the next w lines each contain a string of letters and punctuations, namely the wish, which will contain at most 200 characters. 

Each wish contains one or more sentences, and each sentence is terminated by a '!'. The first letter of each sentence is in uppercase, and other letters will be always in lowercase. No other characters apart from '!', spaces and letters will appear in the sentence. You may assume that each wish is correct in grammar. 

Output

You are required to give girls' response according to the input. For each wish, if it is talking to all the girls, print 'All', or otherwise print the list of girls that it is talking to (names are separated by a single space) in the order that they appear in the name list. Then print a semicolon followed by a space, and the response such as 'hehe' and 'xixi'.

Sample Input

5 5
answer
baiqingr
cedar
juleo
seven
Happy girls day to all of you!
Happy girls day to all of you!Wish you happy forever!
Happy girls day for answer mm!
Congratulations for cedar mm and seven mm!Wish you more and more beautiful hehe! 
Hello answer hello baiqingr hello juleo would you mind having dinner together!

Sample Output

All: oh
All: hehe
answer: oh
cedar seven: xixi
answer baiqingr juleo: hehe

暑假集训第一周便是模拟题专题练习,模拟题的代码好长啊,有时自己看自己的代码都会迷糊。

这个题目做的好蛋疼啊~~~我wrong了十次才过....... 大哭
#include<stdio.h>
#include<string.h>
int find(char *a,char *b)//b是目标字符串,a是wish
{
    int i,j,count,flag,alen,blen;
    alen=strlen(a);
    blen=strlen(b);
    flag=0;
    for(i=0;i<alen;i++)
    {
       count=0;
       for(j=0;j<blen;j++)
       {
           if(b[j]==a[i+j])
              count++;
       }
       if(i>0&&count==blen&&((a[i-1]==' '||a[i-1]=='!')&&(a[i+j]==' '||a[i+j]=='!')))
           flag=1;
       else if(i==0&&count==blen&&(a[i+j]==' '||a[i+j]=='!'))
           flag=1;
    }
    return flag;
}
void change(char *wish)//记得要把wish变成小写,这样方便判断
{
    int i,len;
    len=strlen(wish);
    for(i=0;i<len;i++)
        if(wish[i]>='A'&&wish[i]<='Z')
            wish[i]+=32;
}
int ren[6];//这是用来记录wish中有哪个人名的
char name[6][30];
char str[500];
char str1[10]={"beautiful"},str2[7]={"pretty"},str3[7]={"lovely"};
int main()
{
    int g,w,i,Flage;
    while(~scanf("%d %d",&g,&w))
    {
        for(i=0;i<g;i++)
            scanf("%s",name[i]);
        getchar();
        while(w--)
        {
            int nword=0,slen;
            gets(str);
            Flage=0;
            change(str);
            memset(ren,0,sizeof(ren));//记得每次都要把这个数组清零
            for(i=0;i<g;i++)
                ren[i]=find(str,name[i]);
            for(i=0;i<g;i++)
            {
                if(ren[i])
                {
                    if(Flage>0)
                        printf(" %s",name[i]);
                    else
                        printf("%s",name[i]);
                    Flage++;
                }
            }
            if(Flage==0)
                printf("All");
            printf(": ");
            slen=strlen(str);
            for(i=0;i<slen;i++)
                if((str[i]>='a'&&str[i]<='z')&&(str[i+1]==' '||str[i+1]=='!'))
                    nword++;
            if(nword<=9) printf("oh\n");
            if(nword>=10)
            {
                if(find(str,str1)||find(str,str2)||find(str,str3))
                    printf("xixi\n");
                else printf("hehe\n");
            }
        }
    }
    return 0;
}






你可能感兴趣的:(poj1677-Girls' Day)