题解 | #计算某字符出现次数#

计算某字符出现次数

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);

}

全部评论

相关推荐

孤寡孤寡的牛牛很热情:为什么我2本9硕投了很多,都是简历或者挂,难道那个恶心人的测评真的得认真做吗
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务