题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
String in1 = s.nextLine();
String in2 = s.nextLine();
String s3 = in1.toUpperCase().replaceAll(in2.toUpperCase(),"");
System.out.print(in1.length() - s3.length());
}
}
大佬的思路是真牛逼
先做两个字符串,然后再全部大写转换(小写也是一样的),然后通过全匹配的方法,成功则返回替换的字符串,失败则返回原始字符串。这样可以获得除去需要匹配的字符,然后再用大字符-小字符的长度即可