题解 | #输出单向链表中倒数第k个结点#
截取字符串
http://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
use std::io::{self, *};
fn main() {
let stdin = io::stdin();
let mut s = String::new();
let mut is_first = true;
for line in stdin.lock().lines() {
let ll = line.unwrap();
if is_first {
s = ll;
is_first = false;
}else{
let k = ll.trim().parse::<usize>().unwrap_or(1);
let (first, _last) = s.split_at(k);
println!("{}",first);
is_first = true;
}
}
}
用 Rust 刷华为机试HJ 文章被收录于专栏
用 Rust 刷 HJ100 题,只需要懂基础 Rust 语法就能看懂