UVA Topic 409-excuses, excuses!

Source: Internet
Author: User
Tags alphabetic character keyword list printf

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 () and would o Ccupy 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 3
Dog
ate
homework
Canary
died
my dog ate my homework.
Can believe my dog died after eating my canary ... And MY homework?
This excuse are 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 believe my dog died after eating my canary ... And MY homework?

Excuse Set #2
I am have a superhighway built in my bedroom.
There was a thermonuclear war!

"Code":

/********************************* * Date: 2013-4-29 * Author: SJF0115 * question number: Title 409-excuses, excuses! * Source: Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_ PROBLEM&AMP;PROBLEM=350 * Results: AC * Source: UVA * Summary: **********************************/#include <stdio.h> #include &
Lt;string.h> Char keywords[21][21];
Char str[21][101]; Match int match (char Temp[],int M) {for (int i = 0;i < m;i++) {if (strcmp (temp,keywords[i]) = = 0) {//printf ("%s", tem
			p);
		return 1;
}} return 0;
	} int main () {int i,j,m,n,k,max,maxindex,case = 1;
	Char temp[21];
	int count[21];  
	Freopen ("C:\\users\\xiaosi\\desktop\\acm.txt", "R", stdin);
		while (scanf ("%d%d\n", &m,&n)! = EOF) {memset (count,0,sizeof (int) *n);
		Max =-1;
		Enter keywords for (i = 0;i < m;i++) {gets (keywords[i]);
			}//input excuses for (i = 0;i < n;i++) {gets (str[i]);
			int len = strlen (Str[i]);
				for (j = 0;j < Len;) {k = 0; Extract the word while (str[i][J] >= ' a ' && str[i][j] <= ' z ') | | (Str[i][j] >= ' A ' && str[i][j] <= ' Z '))
					{//Convert to lowercase if (str[i][j] >= ' A ' && str[i][j] <= ' Z ') {temp[k++] = str[i][j]-' a ' + ' a ';
					} else{temp[k++] = str[i][j];
				} j + +;
				} j + +;
				Temp[k] = ' + ';
				and keyword matching if (match (temp,m)) {Count[i] + +;
			}}//maximum number of excuses keywords if (max < count[i]) {max = count[i];
		}}//for//Output printf ("Excuse Set #%d\n", case);
		case++;
			Worst excuses for (i = 0;i < n;i++) {if (Max = = Count[i]) {puts (str[i]);
	}} printf ("\ n");
} return 0;

	
 }


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.