Excuses, Excuses! (map , string )

Excuses, Excuses!

Problem Description

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

Input to your program will consist of multiple sets of data.

Line 1 of each set will contain exactly two integers. The first number (1 <= K <= 20) defines the number of keywords to be used in the search. The second number (1 <= E <= 20) defines the number of excuses in the set to be searched.

Lines 2 through K+1 each contain exactly one keyword.

Lines K+2 through K+1+E each contain exactly one excuse.

All keywords in the keyword list will contain only contiguous lower case alphabetic characters of length L (1 <= L <= 20) and will occupy columns 1 through L in the input line.

All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [SPMamp".,!?&] not including the square brackets and will not exceed 70 characters in length.

Excuses will contain at least 1 non-space character.

Output

For each input set, you are to print the worst excuse(s) from the list.

The worst excuse(s) is/are defined as the excuse(s) which contains the largest number of incidences of keywords.

If a keyword occurs more than once in an excuse, each occurrence is considered a separate incidence.

A keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.

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.

Sample Input

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?

Sample Output

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!
#include<iostream>
# include<map>
#include<cstdio>
# include<cstring>
# include<algorithm>
# include<sstream>
# include<string>
# include<cctype>
using namespace std;
const int maxn=1000;

string ch[maxn];
string str[maxn];
string str1[maxn];
int num[maxn];
string hh,ww;
int main()
{
    int n,m,maax;
    int cas=0;
    while(cin>>n>>m)
    {
        map<string,int > ma;
        ma.clear();
        maax=0;
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
        {
            cin>>ch[i];
            ma[ch[i]]=1;
        }
        getchar();                         //   又是这里忘记 getchar 哭晕啊
        for(int j=1; j<=m; j++)
        {

            getline(cin,str[j]);
            str1[j]=str[j];
            for(int h=0;h<str[j].length();h++)
               if(isalpha(str[j][h])) str[j][h]=tolower(str[j][h]);    //牢记tolower用法
               else
                    str[j][h]=' ';
            stringstream  ss(str[j]);
            while(ss>>hh)
              {
                  if(ma[hh]==1)  num[j]+=1;
                  if(num[j]>maax)  maax=num[j];
              }
        }
           printf("Excuse Set #%d\n",++cas);
             for(int i=1;i<=m;i++)
            {
              if(num[i]==maax&&maax!=0)
                  cout<<str1[i]<<endl;
             }
             cout<<endl;
    }
    return 0;
}

Excuses, Excuses! (map , string )

时间: 2024-10-25 09:04:44

Excuses, Excuses! (map , string )的相关文章

UVA (POJ 1598)Excuses, Excuses!

Excuses, Excuses! Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Excuses, Excuses!  Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid ser

UVA之409 - Excuses, Excuses!

 Excuses, Excuses!  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

Excuses, Excuses! UVA 409

#include <stdio.h> #include <string.h> #include <ctype.h> int get_word(int); void convert_word(); int str_cmp(); char key[100][100];//保存关键词 char word[100];//保存从excuse中提取出来的词 char exc[100][100];//保存excuses int cnt[100];//记录每个excuse中keywor

POJ1598 ZOJ1315 HDU1606 UVA409 UVALive5493 Excuses, Excuses!【文本】

Excuses, Excuses! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4701 Accepted: 1602 Description 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 t

javaBean与Map&lt;String,Object&gt;互转

1. 为什么要实现javaBean与Map<String,Object>相互转换? 用过spring的都知道spring的MVC框架中有一个BaseCommandController对象,利用这个对象我们就可以很方便的将从客户端传递过来的参数封装到一个JavaBean对象中去,而不需要我们request.getParameter("name");bean.setName(name);了,从而也简化了不少的工作.如果大家用过BeanUtils.populate的话,就知道,这

今天学会了对List&lt;Map&lt;String,Object&gt;&gt;的排序

Collections.sort(dyList, new Comparator<Map<String, Object>>() { public int compare(Map<String, Object> arg0, Map<String, Object> arg1) { int map1value=0; int map2value=0; if(arg0.get("getlicenseDate")!=null&&!arg

List&lt;map&lt;String,Object&gt;&gt;

List<Map<String, Object>> list = sendService.getApproveMsgToMap(); //第一种 //遍历map for (Map<String, Object> m : list) { for (String k : m.keySet()) { System.out.println(k + " : " + m.get(k)); } } //第二种 for (int i = 0; i < list

Struts2标签遍历List&lt;Map&lt;String, String&gt;&gt;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private List<Map<String, String>> list; @Override

poj 2945 Find the Clones (map+string,hash思维)

Find the Clones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7498   Accepted: 2780 Description Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship