题解 | #计算某字符出现次数#
计算某字符出现次数
http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1
use std::io;
pub fn main() { let mut s = String::new();
let mut c = String::new();
io::stdin()
.read_line(&mut s)
.expect("Fail to read this line!");
io::stdin()
.read_line(&mut c)
.expect("Fail to read this line!");
// println!("string is {}, char is {}", s, c);
// Count all the chars use lowercase let s = String::from(s.to_ascii_lowercase().trim()); let c = String::from(c.to_ascii_lowercase().trim()); let mut count: u32 = 0; for i in s.chars() { for j in c.chars() { if i == j { count += 1; } } }
println!("{}", count);
}