ZOJ 1315,HDU 1606,Excuses, Excuses!

算法竞赛上推荐的题目,基础题,刷~~~
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=315

/**//*
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=315
*/

#include
<stdio.h>
#include
<string.h>
#include 
<ctype.h>

int main()
{
    
char keywords[25][25],excuse[25][80],tmp_s[80];
    
int i,j,t,lgth,x,max,k,e,test=1,c[25]={0};
    
while(scanf("%d%d",&k,&e)!=EOF)
    
{
        
for(i=0;i<k;i++)
            scanf(
"%s",keywords[i]);
        getchar();
        max
=-1;
        
for(i=0;i<e;i++)
        
{
            gets(excuse[i]);c[i]
=0;
            j
=x=0;lgth=(int)strlen(excuse[i]);
            
for(;j<=lgth;j++)
            
{
                
if( isalpha(excuse[i][j]) )
                    tmp_s[x
++]=tolower(excuse[i][j]);
                
else
                
{
                    tmp_s[x]
='\0';
                    
for(t=0;t<k;t++)
                    
{
                        
if( strcmp(keywords[t],tmp_s)==0 )
                        
{
                            c[i]
++;
                            
break;
                        }

                    }

                    x
=0;
                }

            }

            
if(max<c[i])max=c[i];
        }

        printf(
"Excuse Set #%d\n",test++);
        
for(i=0;i<e;i++)
            
if(c[i]==max)
                printf(
"%s\n",excuse[i]);
        printf(
"\n");
    }

    
return 0;
}


你可能感兴趣的:(ZOJ 1315,HDU 1606,Excuses, Excuses!)