心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
从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;
}
posted on 2011-04-07 12:50 lee1r 阅读(500) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:字符串处理

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理