题解 | #计算某字符出现次数#
计算某字符出现次数
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
use std::io::{self, BufRead};
fn main() {
let stdin = io::stdin();
let mut strr=String::new();
let mut aim=String::new();
stdin.read_line(&mut strr).expect("faled");
stdin.read_line(&mut aim).expect("faled");
let low_strr=strr.to_lowercase();
let ch=aim.to_lowercase().chars().next();
if let Some(ch)=ch{
let count=low_strr.matches(ch).count();
//println!("{}",low_strr);
println!("{}",count);
}
else{
println!("invalid");
}
}
腾讯云智研发成长空间 294人发布