第一个点始终过不了。。。

use std::io;
fn main() {
    let mut score: Vec<bool> = vec![];
    'out: loop {
        let mut line = String::new();
        io::stdin().read_line(&mut line).expect("stdin");

        for word in line.chars() {
            match word {
                'W' => score.push(true),
                'L' => score.push(false),
                'E' => break 'out,
                _ => {}
            };
        }
    }
    final_result(&score, 11);
    final_result(&score, 21);
}

fn final_result(score: &Vec<bool>, choice: i32) {
    let mut w = 0;
    let mut l = 0;

    let length = score.len() as i32;
    if length == 0 {
        println!("0:0");
    }

    for &i in score {
        if i {
            w += 1;
        } else {
            l += 1;
        }

        if (w >= choice || l >= choice) && ((w - l).abs() >= 2) {
            println!("{}:{}", w, l);
            w = 0;
            l = 0;
        }
    }
    println!("{}:{}", w, l);
    println!("");
}

1 条评论

  • @ 2021-10-06 21:06:11

    看了别人的题解才发现判断0:0写错了,我是傻逼
    ```rust
    use std::io;
    fn main() {
    let mut score: Vec<bool> = vec![];
    'out: loop {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("stdin");

    for word in line.chars() {
    match word {
    'W' => score.push(true),
    'L' => score.push(false),
    'E' => break 'out,
    _ => {}
    };
    }
    }
    final_result(&score, 11);
    final_result(&score, 21);
    }

    fn final_result(score: &Vec<bool>, choice: i32) {
    let mut w = 0;
    let mut l = 0;

    for &i in score {
    if i {
    w += 1;
    } else {
    l += 1;
    }

    if (w >= choice || l >= choice) && ((w - l).abs() >= 2) {
    println!("{}:{}", w, l);
    w = 0;
    l = 0;
    }
    }
    println!("{}:{}", w, l);
    println!("");
    }
    ```

  • 1

信息

ID
1217
难度
7
分类
字符串 点击显示
标签
递交数
18717
已通过
4282
通过率
23%
被复制
33
上传者