UVa 409 WA谢谢
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=350&mosmsg=Submission+received+with+ID+12131129
意思就是寻找含给定单词个数最多的句子。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct MyStruct
{
string str;
string str1;
int num;
};
int main()
{
MyStruct MS[1000];
int n,m;
vector<string> svec;
int i,j;
int cas=1;
int maxnum;
while(cin>>n>>m)
{
maxnum=0;
svec.clear();
for(i=0;i!=n;++i)
{
string str;
cin>>str;
svec.push_back(str);
}
getchar();
for(i=0;i!=m;++i)
getline(cin,MS[i].str1);
for(i=0;i!=m;++i)
{
for(j=0;j!=MS[i].str1.size();++j)
if(MS[i].str1[j]>='A'&&MS[i].str1[j]<='Z')
MS[i].str+=MS[i].str1[j]-'A'+'a';
else
MS[i].str+=MS[i].str1[j];
}
for(i=0;i!=m;++i)
{
MS[i].num=0;
string::iterator begin=MS[i].str.begin();
string::iterator end=begin+1;
while(true)
{
for(;end!=MS[i].str.end()&&(*end)>='a'&&(*end)<='z';++end);
string stri(begin,end);
vector<string>::iterator iter=find(svec.begin(),svec.end(),stri);
if(iter!=svec.end())
MS[i].num++;
for(;end!=MS[i].str.end()&&((*end)<'a'||(*end)>'z');++end);
begin=end;
if(end!=MS[i].str.end())
++end;
if(MS[i].num>maxnum)
maxnum=MS[i].num;
if(begin==MS[i].str.end())
break;
}
}
cout<<"Excuse Set #"<<cas++<<endl;
for(j=0;j!=m;++j)
if(MS[j].num==maxnum)
cout<<MS[j].str1<<endl;
cout<<endl;
}
return 0;
}