题解 | #字符串最后一个单词的长度#

字符串最后一个单词的长度

http://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da

use std::io;

fn main() { // loop { let mut s = String::new(); let a = io::stdin() .read_line(&mut s) .expect("Fail to read this line!");

    let mut c: u32 = 0;
    for _si in s.split_whitespace() {
        c = c + 1;
    }

    let mut d: u32 = 0;
    for si in s.split_whitespace() {
        d = d + 1;
        if d == c {
            println!("{}", si.len());
        }
    }

// if a == 1 { // break; // } else { // continue; // } // } }

全部评论

相关推荐

06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务