409 - Excuses, Excuses!

来源:互联网 发布:平面设计书籍 知乎 编辑:程序博客网 时间:2024/03/28 18:04
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int cmp(const void *p1,const void *p2){    return *(int*)p1-*(int*)p2;}int main(){    int n,m,i,j,_i,_j,MAX,num(0);    int count[25];    char word[25][25],str[25][150],str1[130][80];    while(cin>>n>>m)    {        num++;        getchar();        memset(word,0,sizeof(word));        memset(str,0,sizeof(str));        memset(count,0,sizeof(count));        for(i=0; i<n; i++)            cin>>word[i];            getchar();        for(i=0; i<m; i++)            fgets(str[i],150,stdin);        _i=_j=MAX=0;        for(i=0; i<m; i++)        {            memset(str1,0,sizeof(str1));            for(j=0; j<strlen(str[i]); j++)                if(tolower(str[i][j])>='a'&&tolower(str[i][j])<='z')                    str1[_i][_j++]=tolower(str[i][j]);                else                {                    _i++;                    _j=0;                }            for(j=0; j<n; j++)                for(_j=0; _j<_i; _j++)                {                    if(strcmp(word[j],str1[_j])==0)                        count[i]++;                    if(MAX<count[i])                        MAX=count[i];                }               // cout<<str[0]<<endl;        }        cout<<"Excuse Set #"<<num<<endl;        //qsort(count,i,sizeof(int),cmp);        for(i=0; i<m; i++)            if(MAX==count[i])                cout<<str[i];        cout<<endl;    }    return 0;}