Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于过了!!!附代码!!!

Posted by wocha at 2012-07-10 15:35:58 on Problem 1677
In Reply To:Re:wa无数次!!测试全过求大牛指教!!!! Posted by:wocha at 2012-07-10 15:35:15
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int NumberWords(char s[])
{
    int i,j,n,m,k,l;
    n=0;
    l=strlen(s);
    for(i=0;i<l;i++)
    {
        if((s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')&&(s[i+1]==' '||s[i+1]=='!'))
        {
            n++;
        }
    }
    return n;
}
int girl[333];
char  str1[222][333];
int FindWord(char s[])
{
    int len=strlen(s);
    char d[343];
    int i,j;
    for(i=0,j=0;i<len;i++)
    {
        if(s[i]==' ')
        {
            if(strncmp(s+j,"beautiful",9)==0)
            {
if(i-j==9)
                return 1;
            }
            if(strncmp(s+j,"pretty",6)==0)
            {
 if(i-j==6)
                return 1;
            }
            if(strncmp(s+j,"lovely",6)==0)
            {
 if(i-j==6)
                return 1;
            }
            if(strncmp(s+j,"Beautiful",9)==0)
            {
 if(i-j==9)
                return 1;
            }
            if(strncmp(s+j,"Pretty",6)==0)
            {
 if(i-j==6)
                return 1;
            }
            if(strncmp(s+j,"Lovely",6)==0)
            {
 if(i-j==6)
                return 1;
            }
            j=i+1;
        }
    }
    return 0;
}
void FindGirls(char s[],int n)
{
 int i,j,m,k,l;
 l=strlen(s);
 for(i=0,j=0;i<l;i++)
 {
   if(s[i]==' ')
   {
           for(k=0;k<n;k++)
         {
            char temp[333];
            strcpy(temp,str1[k]);
            temp[0]-=32;
             if(strncmp(s+j,str1[k],strlen(str1[k]))==0||strncmp(s+j,temp,strlen(str1[k]))==0)
             {
                    if(i-j==strlen(str1[k]))
                   {
                    girl[k]=1;
                  
                    break;
                    }
             }
         }
         j=i+1;
   }
 }
}
int main()
{
    int i,j,n,m,k,l,o,p;
    char str2[222];
    while(scanf("%d%d",&n,&m)!=-1)
    {
    
        for(i=0;i<n;i++)
        {
            scanf("%s",str1[i]);
        }
        getchar();
        while(m--)
        {
           gets(str2);
            int len=strlen(str2);
            for(i=0;i<len;i++)
             if(str2[i]=='!')

              str2[i]=' ';
           for(i=0;i<=n;i++)
            girl[i]=0;
            FindGirls(str2,n);
           int count=0;
           for(i=0;i<n;i++)
           {
                if(girl[i]!=0)
                  count++;
           }

           if(count==0)
           {
              printf("All:");
              if(NumberWords(str2)<=9)
              {
                    printf(" oh\n");
              }
              else
              {
                    if(FindWord(str2))
                    {
                    printf(" xixi\n");
                    }
                    else
                    {
                        printf(" hehe\n");
                    }
                }
           }
           else
           {
                for(i=0;i<n;i++)
                {

               if(girl[i]!=0)
                   {
                        if(count==1)
                        {
                            printf("%s:",str1[i]);
                            break;
                        }
                    else
                    {
                        printf("%s ",str1[i]);
                        count--;
                    }
                   }
                    
                }
                if(NumberWords(str2)<=9)
              {
                    printf(" oh\n");
              }
              else


              {
                    if(FindWord(str2))
                    {
                    printf(" xixi\n");
                    }
                    else
                    {
                        printf(" hehe\n");
                    }
                }
            }

        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator