题解 | #字符串分隔#

字符串分隔

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

幸好,rust也支持类似python的字符串切片

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

fn main() {
    let stdin = io::stdin();
    // unsafe {
    //     for line in stdin.lock().lines() {
    //         let ll = line.unwrap();
    //         let numbers: Vec<&str> = ll.split(" ").collect();
    //         let a = numbers[0].trim().parse::<i32>().unwrap_or(0);
    //         let b = numbers[1].trim().parse::<i32>().unwrap_or(0);
    //         print!("{}\n", a + b);
    //     }
    // }
    
    let mut line = stdin.lock().lines().next().unwrap().unwrap();

    let padding_length = (8 - line.len() % 8) % 8;

    for _ in 0..padding_length {
        line.push('0');
    }

    let mut start =0;
    let mut end = 8;

    while end <= line.len(){
        println!("{}",&line[start..end]);
        start = end;
        end += 8;
    }

}

#rust#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务