UVa 409 Excuses, Excuses!

UVa 409 Excuses, Excuses!
从excuse中统计keyword的数量,找到最大值并输出对应的excuse。
以下是我的代码:
#include < iostream >
#include
< string >
#include
< set >
#include
< cstdio >
#include
< cctype >
using   namespace  std;
const   int  kMaxm( 27 );

struct  Excuse
{
    Excuse():counter(
0 ) {}
    
string  words;
    
int  counter;
};

int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
int  T( 0 ),n,m;
    
while (cin >> n >> m)
    {
        
set < string >  keywords;
        
for ( int  i = 1 ;i <= n;i ++ )
        {
            
string  t;
            cin
>> t;
            keywords.insert(t);
        }
        getchar();
        Excuse r[kMaxm];
        
for ( int  i = 1 ;i <= m;i ++ )
        {
            getline(cin,r[i].words);
            
string  t(r[i].words);
            
for ( int  j = 0 ;j < t.size();j ++ )
                t[j]
= tolower(t[j]);
            
for ( int  j = 0 ;j < t.size();j ++ )
            {
                
string  t2;
                
while (isalpha(t[j]))
                {
                    t2
+= t[j];
                    j
++ ;
                }
                
if (keywords.count(t2))
                    r[i].counter
++ ;
            }
        }
        
int  max_ans( 0 );
        
for ( int  i = 1 ;i <= m;i ++ )
            
if (max_ans < r[i].counter)
                max_ans
= r[i].counter;
        T
++ ;
        cout
<< " Excuse Set # " << T << endl;
        
for ( int  i = 1 ;i <= m;i ++ )
            
if (r[i].counter == max_ans)
                cout
<< r[i].words << endl;
        cout
<< endl;
    }

    
return   0 ;
}

你可能感兴趣的:(UVa 409 Excuses, Excuses!)