题解 | #字符串分隔#

字符串分隔

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

use std::io::{self, *};

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr = s.trim().as_bytes();
    // 有几个8
    let a = arr.len() / 8;
    // 余数8
    let b = arr.len() % 8;
    if a > 0 {
        for i in 0..a {
            for j in 0..8 {
                print!("{}", arr[i * 8 + j] as char);
            }
            println!();
        }
    }
    if b > 0 {
        arr.iter()
            .skip(arr.len() - b)
            .for_each(|&x| print!("{}", x as char));
        for _ in 0..8 - b {
            print!("0");
        }    
        println!();

    }

}

全部评论

相关推荐

机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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