Uva409_excuses, excuses! (Small petition string topic)

Source: Internet
Author: User
Tags alphabetic character keyword list

Problem Solving Report

Test instructions

Find the string that includes the most words. There are multiple output sequentially

Ideas:

The dictionary tree exploded.

#include <cstdio> #include <cstring> #include <iostream>using namespace Std;int k,e,num[100],cnt;    struct node{int v; Node *next[26];};    Node *newnode () {node *p=new node;    p->v=0;    int i;    for (i=0;i<26;i++) p->next[i]=null; return p;}    void AddNode (node *root,char *str) {int i,l=strlen (str);    Node *p=root;        for (i=0;i<l;i++) {int t=str[i]-' a ';        if (p->next[t]==null) P->next[t]=newnode ();    p=p->next[t]; } p->v=1;}    int findd (node *root,char *str) {node *p=root;    int I,l=strlen (str);        for (i=0;i<l;i++) {int t=str[i]-' a ';        if (P->next[t]==null) return 0;    p=p->next[t]; } return p->v;}    int main () {char ch[100],str[100][100];    int i,j,m,kk=1;        while (~SCANF ("%d%d", &k,&e)) {node *root=newnode ();            for (i=0;i<k;i++) {scanf ("%s", ch);        AddNode (ROOT,CH);      } getchar ();  int maxx=0;            for (i=0;i<e;i++) {fgets (Str[i],100,stdin);            int L=strlen (str[i]);            m=0;            cnt=0; for (j=0;j<l;j++) {if (str[i][j]>= ' a ' &&str[i][j]<= ' z ') | |                (str[i][j]>= ' A ' &&str[i][j]<= ' Z '))                    {if (str[i][j]>= ' A ' &&str[i][j]<= ' Z ') ch[m++]=str[i][j]+32;                else Ch[m++]=str[i][j];                    } else {ch[m]=0;                    m=0;                if (FINDD (root,ch)) cnt++;            }} if (maxx<cnt) maxx=cnt;        num[i]=cnt;        } printf ("Excuse Set #%d\n", kk++);        for (i=0;i<e;i++) {if (Num[i]==maxx) printf ("%s", Str[i]);    } printf ("\ n"); } return 0;}

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 and 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 () a nd 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 marks [SPMamp".,!? &] not including the square brackets and would not be exceed characters in length.
  • Excuses'll 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!



Uva409_excuses, excuses! (Small petition string topic)

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.