題目鏈接:http://poj.org/problem?id=1598
技巧:句子中單詞的查找填大∨ㄌ澹可以通過替換掉不是字母的字符 胳岂,然后用indexof查找
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n,m;
String[] keyw = null;
String[] excuse = null;
String[] excuseLower = null;
int [] count;
int max;
int cases = 1;
while(cin.hasNext()){
String[] t = cin.nextLine().split(" ");
n = Integer.parseInt(t[0]);
m = Integer.parseInt(t[1]);
keyw = new String[n];
excuse = new String[m];
excuseLower = new String[m];
count = new int[m];
max = 0;
for (int i = 0; i < n; i++) {
keyw[i] = cin.nextLine().toLowerCase();
}
for (int i = 0; i < m; i++) {
excuseLower[i] = cin.nextLine();
excuse[i] = excuseLower[i].toLowerCase();
String temp = " ";
for (int j = 0; j < excuse[i].length(); j++) {
if(Character.isLetter(excuse[i].charAt(j)))
temp+=excuse[i].charAt(j);
else
temp+="#";
}
for (int j = 0; j < n; j++) {
if (temp.indexOf("#"+keyw[j]+"#")>0) {
count[i]++;
}else if(temp.indexOf(keyw[j]+"#")==0){
count[i]++;
}else if(temp.indexOf("#"+keyw[j])==(temp.length()-keyw[j].length()-1)){
count[i]++;
}
}
if(count[i]>max)
max = count[i];
}
System.out.println("Excuse Set #"+cases++);
for (int i = 0; i < m; i++) {
if(count[i]==max)
System.out.println(excuseLower[i]);
}
System.out.println("");
}
// printAr(keyw);
// printAr(excuse);
}
static void printAr(Object [] ar){
for (Object object : ar) {
System.out.println(object);
}
}
```