标签:style blog http io ar color os sp for
Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case.
Input to your program will consist of multiple sets of data.
SPMamp
".,!?&] not including the square brackets and will not exceed 70 characters in length.For each input set, you are to print the worst excuse(s) from the list.
For each set of input, you are to print a single line with the number of the set immediately after the string ``Excuse Set #". (See the Sample Output). The following line(s) is/are to contain the worst excuse(s) one per line exactly as read in. If there is more than one worst excuse, you may print them in any order.
After each set of output, you should print a blank line.
5 3 dog ate homework canary died My dog ate my homework. Can you believe my dog died after eating my canary... AND MY HOMEWORK? This excuse is so good that it contain 0 keywords. 6 5 superhighway crazy thermonuclear bedroom war building I am having a superhighway built in my bedroom. I am actually crazy. 1234567890.....,,,,,0987654321?????!!!!!! There was a thermonuclear war! I ate my dog, my canary, and my homework ... note outdated keywords?
Excuse Set #1 Can you believe my dog died after eating my canary... AND MY HOMEWORK? Excuse Set #2 I am having a superhighway built in my bedroom. There was a thermonuclear war!
还是串处理。。
题意:给一个字典,然后给e行串 问哪行串里面的出现的单词次数最多,有多个则输出多个
思路:字典扔set里。。然后gets成行读进来转换成单词哎个查询。。然后就完了。。
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #define ll long long #define maxn 360 #define pp pair<int,int> #define INF 0x3f3f3f3f #define max(x,y) ( ((x) > (y)) ? (x) : (y) ) #define min(x,y) ( ((x) > (y)) ? (y) : (x) ) using namespace std; char tem[88],exc[22][77]; int k,e,p,ans[22]; int main() { int cas=1; while(~scanf("%d%d",&k,&e)) { getchar(); memset(ans,0,sizeof(ans)); string x;set <string> s; while(k--) { cin>>x; s.insert(x); } getchar(); for(int i=0;i<e;i++) { gets(exc[i]); int len=strlen(exc[i]); for(int j=0;j<=len;) if(isalpha(exc[i][j])) { p=0;tem[p++]=tolower(exc[i][j]);j++; while(isalpha(exc[i][j])) tem[p++]=tolower(exc[i][j++]); tem[p++]='\0';string y(tem); if(s.count(y)) ans[i]++; } else j++; } printf("Excuse Set #%d\n",cas++); int Max=-INF; for(int i=0;i<e;i++) Max=max(Max,ans[i]); for(int i=0;i<e;i++) if(ans[i]==Max) printf("%s\n",exc[i]); puts(""); } return 0; }
标签:style blog http io ar color os sp for
原文地址:http://blog.csdn.net/qq_16255321/article/details/41329489