UVA 409-excuses, excuses! Simulation

Source: Internet
Author: User
Tags alphabetic character keyword list

Excuses, excuses!Time limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus

Description


excuses, excuses!

Judge Ito is has 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 have asked that you write a program th At'll search for a list of keywords in a list of excuses identifying lame excuses. Keywords can is matched in a excuse regardless of case.

Input

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

    • Line 1 of each set would contain exactly the integers. The first number (  ) defines the number of keywords to is used in the search. The second number (  ) defines the number of excuses in the and the set to is 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 would contain only contiguous lower case alphabetic characters of length  l  (  ) and would occupy columns 1 through  L  in the input line.
    • all excuses can contain no upper or lower case alphanumeric character, a space, or any of the following punctuation m Arks [ spmamp .,!? &] not including the square brackets and would not be exceed characters in length.
    • excuses would contain at least 1 non-space character.
Output

For each of the input set, you is 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 occurrance is considered a separate incidence.
    • A keyword "occurs" in an excuse if and only if it exists in the string in contiguous form and are delimited by the Beginni Ng or end of the line or any non-alphabetic character or a space.

For each set of input, you is 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) of 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 3dogatehomeworkcanarydiedMy dog ate my homework. Can believe my dog died after eating my canary ... and MY homework? This excuse are so good the it contain 0 keywords.6 5superhighwaycrazythermonuclearbedroomwarbuildingI am having a Superhi Ghway 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 #1Can believe my dog died after eating my canary ... and MY homework? Excuse Set #2I am has a superhighway built in my bedroom. There was a thermonuclear war!

Test instructions: Give two number m,n. That is, the M keyword, n the pretext, which excuse contains the most of the keyword, on the output of the current pretext


#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include < Iostream>using namespace Std;char Key[20][20];char ex[20][110];int cnt[110];int n,m;int Find (char *str) {char a[110]    ;    int i,j=0;    int count = 0; for (i=0;str[i]!= '; i++) {if (str[i]>= ' A ' &&str[i]<= ' Z ' | | Str[i]>= ' a ' &&str[i]<= ' z ')//The keyword is all lowercase, so convert all uppercase letters in the excuses into lowercase {if (str[i]>= ' a ' &&str[            i]<= ' Z ') {a[j]=str[i]+32;            } else a[j]=str[i];        j + +; } else//because the statement contains other characters, so when it is other characters {a[j] = ' n ';//means re-replaced with another word for (j = 0; j < m;                {if (strcmp (a,key[j]) = = 0) {count++; }} j = 0;//takes out the next word;}} return count;}    int main () {int i;    int t=1;    int Maxx; while (~SCANF ("%d%d", &m, &n)) {GetChar ();        maxx=0;        memset (cnt,0,sizeof (CNT));        for (i=0; i<m; i++) gets (Key[i]);        for (i=0; i<n; i++) gets (Ex[i]);        for (i=0; i<n; i++) Cnt[i]=find (Ex[i]);        for (i=0; i<n; i++) Maxx=max (Maxx,cnt[i]);        printf ("Excuse Set #%d\n", t++);            for (i=0; i<n; i++) {if (Maxx==cnt[i]) {puts (ex[i]);    }} printf ("\ n"); } return 0;}


UVA 409-excuses, excuses! Simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.