跳到主要內容

UVA409

 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 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 ( tex2html_wrap_inline30 ) defines the number of keywords to be used in the search. The second number ( tex2html_wrap_inline32 ) 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 ( tex2html_wrap_inline42 ) 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 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 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!


--------------------------------------------------------------------------




import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class UVA409{

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner sc = new Scanner(System.in);
  
  int count = 1;
  
  while(sc.hasNext())
  {
   int K = sc.nextInt();
   
   int E = sc.nextInt();
   
   System.out.println("Excuse Set #"+count);
   
   sc.nextLine();
   
   String K_box [] = new String[K];
   String E_box [] = new String[E];
   
   int print[] = new int[E];
   
   int max = 0;
   
   for(int i=0;i<K;i++)
    K_box[i] = sc.nextLine();
   
   for(int i=0;i<E;i++)
    E_box[i] = sc.nextLine();
  
   Set st = new HashSet();
   
   for(int i =0;i<E;i++)
   {
    String temp="";
    
    for(int e=0;e<E_box[i].length();e++)
    {
     if((E_box[i].charAt(e)>='a' && E_box[i].charAt(e)<='z') || (E_box[i].charAt(e)>='A' && E_box[i].charAt(e)<='Z'))
     {
      //排除非字情況
      temp = temp + E_box[i].charAt(e);
     }
     else{
     
      st.add(temp.toLowerCase());
      temp="";
     }
    }
    
    for(int k =0;k < K; k++)
    {
     //搜尋每一筆句子 含有多少個keyword
     if(st.contains(K_box[k])){
      
      print[i]++;
     }
    }
    
    
    st.clear();
   }
   
   for(int p=0;p<E;p++)
   { 
    if(max<print[p])
     max=print[p];
   }
   
   for(int p=0;p<E;p++)
   {
    if(max==print[p])
    System.out.println(E_box[p]);
   }
   
   System.out.println();
   count++;
   
  }
  sc.close();
 }

}


--------------------------------------------------------------------------


留言

這個網誌中的熱門文章

UVA11349

J - Symmetric Matrix Time Limit: 1 sec Memory Limit: 16MB You`re given a square matrix M. Elements of this matrix are M ij : {0 < i < n, 0 < j < n}. In this problem you'll have to find out whether the given matrix is symmetric or not. Definition: Symmetric matrix is such a matrix that all elements of it are non-negative and symmetric with relation to the center of this matrix. Any other matrix is considered to be non-symmetric. For example: All you have to do is to find whether the matrix is symmetric or not. Elements of a matrix given in the input are -2 32  <= M ij  <= 2 32  and 0 < n <= 100. INPUT: First line of input contains number of test cases T <= 300. Then T test cases follow each described in the following way. The first line of each test case contains n - the dimension of square matrix. Then n lines follow each of then containing row i. Row contains exactly n elements separated by a space character. j-th number in row i is the elem

UVA11461

A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive). Input The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤ b ≤ 100000). Input is terminated by a line containing two zeroes. This line should not be processed. Output For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive). Sample Input 1 4 1 10 0 0 Sample Output 2 3 大意:給兩個數字 求範圍內平方不大於第二個數字的數量 解法: 以最大數取根號後往回看 import java.util.Scanner; public class UVA11461 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int start = sc.nextInt(); int last = sc.nextInt(); if (last == 0) break; System.o

UVA11005

Problem B Cheapest Base Input:  Standard Input Output:  Standard Output When printing text on paper we need ink. But not every character needs the same amount of ink to print: letters such as 'W', 'M' and '8' are more expensive than thinner letters as ' i ', 'c' and '1'. In this problem we will evaluate the cost of printing numbers in several bases. As you know, numbers can be expressed in several different bases. Well known bases are binary (base 2; digits 0 and 1), decimal (base 10; digits 0 to 9) and hexadecimal (base 16; digits 0 to 9 and letters A to F). For the general base  n  we will use the first  n  characters of the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", which means the highest base in this problem is 36. The lowest base is of course 2. Every character from this string has an associated cost, represented by an integer value between 1 and 128. The cost to print a number in a certain base is the s