LeeBlog

导航

HDU 1005 Let the Balloon Rise

水题 。。 就是从给出的字符串中找出出现次数最频繁的那一个。。。

直接暴力。。 给没个字符串一个编号。。 

#include<stdio.h>
#include<string.h>
int n,c,des[1005];
char ch[1005][20];
int search( char str[] )
{
    for( int i = 0; i < c; ++i )
         if( !strcmp( ch[i],str ) )
             return i;
    return c++;
}
int main( )
{
    while( scanf( "%d",&n ),n )
    {
           c = 0;
           memset( ch,0,sizeof( ch ) );
           memset( des,0,sizeof( des ) );
           for( int i = 0; i < n; ++i )
           {
                scanf( "%s",ch[c] );
                int x = search( ch[c] );
                des[x]++;
            }
           int max = 0;
           for( int i = 1; i < c; ++i )
                if( des[i] > des[max] )
                    max = i;
           printf( "%s\n",ch[max] );
           }
    return 0;
}

posted on 2011-05-11 16:54  LeeBlog  阅读(217)  评论(0编辑  收藏  举报