| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怎么老是wa啊,我实在找不出错误了。。大牛们帮帮忙#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define maxSize 71
struct excuse{
//string sentence;
char sentence[maxSize];
int num; //used to record the number of keywords included in the sentence
};
string keyword[21];
struct excuse ex[21];
int main()
{
int k,e; //k denotes number of keywords and e denotes number of excuse
int count=0; //count num of test cases
while(cin>>k>>e){
count++;
//每次进来之时num必须归0
for (int y=0;y<e;y++){
ex[y].num=0;
ex[y].sentence[0]='\0';
}
for (int i=0;i<k;i++)
cin>>keyword[i];
fflush(stdin);
//int k=2,e=2;
for (int j=0;j<e;j++){
string re,w; //
//getline(cin,ex[j].sentence);//string类的getline用法,从流中读到s。可将整个行的输入保存到s里
//string s=ex[j].sentence;
char s[maxSize];
//getline(cin,s);
gets(s);
fflush(stdin);
//ex[j].sentence=s;
// for (int x=0;s[x];x++)
// ex[j].sentence[x]=s[x];
strcpy(ex[j].sentence,s);
istringstream stream(s); // istringstream型变量初始化用string
while(stream >> w) { //istringstream型变量可输出到string
//convert w to lower case and we must control the word to a zimu only
string temp;
for (int t=0;t<w.length();t++)
if ('A'<=w[t]&&w[t]<='Z')
temp+=w[t]+32;
else if ('a'<=w[t]&&w[t]<='z')
temp+=w[t];
//else //delete the letter
// w.erase(w[t]);
for (int q=0;q<k;q++)
if (temp==keyword[q])
ex[j].num++;
//test if w is a keyword
}
}
cout<<"Excuse Set #"<<count<<endl;
int max=0;
for (int p=1;p<e;p++)
if (ex[p].num>ex[max].num)
max=p;
//cout<<ex[max].sentence<<endl;
for (int m=0;m<e;m++)
if (ex[m].num==ex[max].num)
cout<<ex[m].sentence<<endl;
cout<<endl;
// cout<<re<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator