- 乒乓球
 - @ 2021-10-06 21:01:59
 
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 条评论
- 
  OOJ LV 4 @ 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