-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.rs
More file actions
36 lines (32 loc) · 994 Bytes
/
Copy pathtemplate.rs
File metadata and controls
36 lines (32 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::io::Write;
fn main() {
let mut token = Scanner::new(std::io::stdin().lock());
let mut out = std::io::BufWriter::new(std::io::stdout().lock());
}
pub struct Scanner<R> {
reader: R,
buffer: Vec<u8>,
iter: std::str::SplitAsciiWhitespace<'static>,
}
impl<R: std::io::BufRead> Scanner<R> {
pub fn new(reader: R) -> Self {
Self {
reader,
buffer: vec![],
iter: "".split_ascii_whitespace(),
}
}
pub fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.iter.next() {
return unsafe { token.parse().unwrap_unchecked() };
}
self.buffer.clear();
self.reader.read_until(b'\n', &mut self.buffer).unwrap();
self.iter = unsafe {
let slice = std::str::from_utf8_unchecked(&self.buffer);
std::mem::transmute(slice.split_ascii_whitespace())
}
}
}
}