题目:给定两行空的字符串,第一行的字符串包含了部分空白(空格、tab),第二行字符串不包含任何空白,请从第一行字符串中匹配第二行字符串,匹配时忽略空白及tab,输出第一行字符串中第二行字符串出现的次数;
输入:第一行输入小于1K的字符串,包含了部分空白(空格、tab)
第二行输入小于1K的字符串,不包含任何空白
输出:
Abb bn
bb
2
3 import java.util.Scanner; 4 5 6 public class StringProcess { 7 public static void main(String[] args){ 8 Scanner input=new Scanner(System.in); 9 while (input.hasNextLine()){ 10 String str1=input.nextLine(); 11 String str2=input.nextLine(); 12 13 str1=str1.replaceAll("\\s*",""); 14 str1=str1.replaceAll("\t",""); 15 16 int count= 0; 17 for(int i=0;i<str1.length()-str2.length()+1;i++){ 18 if(str1.substring(i,i+str2.length()).equals(str2)) 19 count++; 20 } 21 System.out.println(str1); 22 System.out.println(count); 23 } 24 input.close(); 25 } 26 }