rust stuff(tm)
This commit is contained in:
parent
07a58afaff
commit
3ac8ca1f5e
2 changed files with 7 additions and 23 deletions
|
@ -1,7 +1,4 @@
|
|||
#![feature(iter_array_chunks)]
|
||||
#![feature(round_char_boundary)]
|
||||
#![feature(iter_collect_into)]
|
||||
#![feature(pattern)]
|
||||
#![feature(pattern, iter_array_chunks, round_char_boundary, iter_collect_into)]
|
||||
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
|
@ -17,17 +14,16 @@ const BOOLS: &[[&str; 2]] = &[
|
|||
["no", "yes"],
|
||||
];
|
||||
|
||||
fn main() {
|
||||
fn main() -> std::io::Result<()> {
|
||||
let mut input = String::new();
|
||||
let mut stdin = std::io::stdin();
|
||||
let mut stdout = std::io::stdout();
|
||||
|
||||
stdin.read_to_string(&mut input).unwrap();
|
||||
stdin.read_to_string(&mut input)?;
|
||||
|
||||
let bool_locs = find_bools(&input);
|
||||
stdout
|
||||
.write_all(replace_bools(&mut input, bool_locs).as_bytes())
|
||||
.unwrap();
|
||||
|
||||
stdout.write_all(replace_bools(&mut input, bool_locs).as_bytes())
|
||||
}
|
||||
|
||||
type BoolLocs = [[Vec<usize>; 2]; BOOL_COUNT];
|
||||
|
@ -96,14 +92,12 @@ fn find_bools(input: &str) -> [[Vec<usize>; 2]; BOOL_COUNT] {
|
|||
&& char_guard(
|
||||
input[it.1.floor_char_boundary(it.0 - 1)..it.0]
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap(),
|
||||
.last()?,
|
||||
)
|
||||
&& char_guard(
|
||||
input[(last_idx)..(input.ceil_char_boundary(last_idx + 1))]
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap(),
|
||||
.last()?,
|
||||
))
|
||||
.then_some(it.0)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue