-
题目描述:
-
给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。
-
输入:
-
输入只有1组数据。
输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。
-
输出:
-
删除输入的短字符串(不区分大小写)并去掉空格,输出。
-
样例输入:
-
in #include int main() { printf(" Hi "); }
-
样例输出:
-
#clude tma() { prtf("Hi"); }
-
提示:
-
注:将字符串中的In、IN、iN、in删除。
import java.io.IOException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Main
{
public static final boolean DEBUG = false;
public static void main(String[] args) throws IOException
{
BufferedReader cin;
String s, value;
if (DEBUG) {
cin = new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt"));
} else {
cin = new BufferedReader(new InputStreamReader(System.in));
}
s = cin.readLine();
Pattern pat = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
while ((s = cin.readLine()) != null) {
Matcher mat = pat.matcher(s);
String tmp = s;
while (mat.find()) {
value = mat.group(0);
tmp = tmp.replace(value, "");
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < tmp.length(); i++) {
if (tmp.charAt(i) == ' ') continue;
sb.append(tmp.charAt(i));
}
System.out.println(sb.toString());
}
}
}