F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Find Black Hand

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1731    Accepted Submission(s): 429


Problem Description
I like playing game with my friends, although sometimes look pretty naive. Today I invent a new game called find black hand. The game is not about catching bad people but playing on a string.
Now I generate a string S and several short ones s[i], and I define three kinds of operations.
1. Delete: remove the ith character.
2. Insert: in any position, insert a character if you like.
3. Change: change the ith character into another character if you like.
For each short string s[i], we define a function f(i). After several operations on S, we can find a substring of S which is the same to s[i]. And f(i) is the minimal number of operations to achieve. It looks so native that I think every one of you can solve f(i) perfectly. So I join the string S from end to end, and f(i) changes nothing. So the string "bb" is also a substring of string "baaab".
The "black hand" is the short string s[i] whose f(i) is minimal. Now it's your time to find the black hand.
 

Input
There are multiple test cases.
The first line contains a non-empty string S whose length is not more than 100,000.
The next line contains an integer N (1 <= N <= 10) indicating the number of the short string.
Each of the next N lines contains a short non-empty string whose length is not more than 10.
All strings in the input would not have blank and all characters are lower case.
 

Output
For each test case, output a string first indicating the "black hand", and then output an integer indicating the minimal number of the operation. If there are more than one "black hand", please output the smallest one in lexicographical order.
 

Sample Input
aaabbbb 2 alice bob
 

Sample Output
bob 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 09:21:06, Gzip enabled