Skip to main content

Scanner

Struct Scanner 

Source
pub struct Scanner<'a, I: Iterator<Item = &'a str> = SplitAsciiWhitespace<'a>> {
    iter: I,
}

Fields§

§iter: I

Implementations§

Source§

impl<'a> Scanner<'a>

Source

pub fn new(s: &'a str) -> Self

Examples found in repository?
crates/library_checker/src/sample/aplusb.rs (line 6)
4pub fn aplusb(reader: impl Read, mut writer: impl Write) {
5    let s = read_all_unchecked(reader);
6    let mut scanner = Scanner::new(&s);
7    scan!(scanner, a, b);
8    writeln!(writer, "{}", a + b).ok();
9}
More examples
Hide additional examples
crates/aizu_online_judge/src/dpl/dpl_3_c.rs (line 8)
6pub fn dpl_3_c(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, h: [usize; n]);
10    writeln!(writer, "{}", largest_rectangle(&h)).ok();
11}
crates/aizu_online_judge/src/dpl/dpl_1_e.rs (line 8)
6pub fn dpl_1_e(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, s1: Chars, s2: Chars);
10    writeln!(writer, "{}", levenshtein_distance(&s1, &s2)).ok();
11}
crates/library_checker/src/string/zalgorithm.rs (line 8)
6pub fn zalgorithm(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, s: Chars);
10    let z = Zarray::new(&s);
11    iter_print!(writer, @it (0..s.len()).map(|i| z[i]));
12}
13
14#[verify::library_checker("zalgorithm")]
15pub fn zalgorithm_rolling_hash(reader: impl Read, mut writer: impl Write) {
16    let s = read_all_unchecked(reader);
17    let mut scanner = Scanner::new(&s);
18    scan!(scanner, s: Bytes);
19    Mersenne61x1::init(s.len());
20    let h = Mersenne61x1::hash_sequence(s.iter().map(|&c| c as _));
21    let ans = (0..s.len()).map(|i| h.range(..).longest_common_prefix(&h.range(i..)));
22    iter_print!(writer, @it ans);
23}
crates/library_checker/src/number_theory/enumerate_quotients.rs (line 8)
6pub fn enumerate_quotients(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n);
10    let qi = FloorQuotientIndex::new(n);
11    iter_print!(writer, qi.len(); @it qi.values());
12}
crates/aizu_online_judge/src/dpl/dpl_3_a.rs (line 8)
6pub fn dpl_3_a(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, h, w, c: [[u8; w]; h]);
10    let res = largest_square(h, w, |i, j| c[i][j] == 0);
11    writeln!(writer, "{}", res).ok();
12}
Source§

impl<'a, I: Iterator<Item = &'a str>> Scanner<'a, I>

Source

pub fn new_from_iter(iter: I) -> Self

Source

pub fn scan<T>(&mut self) -> <T as IterScan>::Output
where T: IterScan,

Source

pub fn mscan<T>(&mut self, marker: T) -> <T as MarkedIterScan>::Output
where T: MarkedIterScan,

Source

pub fn scan_vec<T>(&mut self, size: usize) -> Vec<<T as IterScan>::Output>
where T: IterScan,

Source

pub fn iter<'b, T>(&'b mut self) -> ScannerIter<'a, 'b, I, T>
where T: IterScan,

Examples found in repository?
crates/library_checker/src/sample/many_aplusb.rs (line 10)
6pub fn many_aplusb(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, t);
10    for (a, b) in scanner.iter::<(usize, usize)>().take(t) {
11        writeln!(writer, "{}", a + b).ok();
12    }
13}
More examples
Hide additional examples
crates/library_checker/src/data_structure/range_kth_smallest.rs (line 11)
6pub fn range_kth_smallest(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q, a: [usize; n]);
10    let wm = WaveletMatrix::new(a);
11    for (l, r, k) in scanner.iter::<(usize, usize, usize)>().take(q) {
12        writeln!(writer, "{}", wm.quantile(l..r, k)).ok();
13    }
14}
crates/library_checker/src/number_theory/factorize.rs (line 10)
6pub fn factorize(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, q);
10    for a in scanner.iter::<u64>().take(q) {
11        let x = prime_factors_flatten(a);
12        write!(writer, "{}", x.len()).ok();
13        for x in x.into_iter() {
14            write!(writer, " {}", x).ok();
15        }
16        writeln!(writer).ok();
17    }
18}
crates/aizu_online_judge/src/grl/grl_3_c.rs (line 12)
6pub fn grl_3_c(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, vs, es, (graph, _): @DirectedGraphScanner::<usize, ()>::new(vs, es));
10    let scc = StronglyConnectedComponent::new(&graph);
11    scan!(scanner, q);
12    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
13        writeln!(writer, "{}", (scc[u] == scc[v]) as u32).ok();
14    }
15}
crates/library_checker/src/tree/lca.rs (line 13)
6pub fn lca_euler_tour(reader: impl Read, mut writer: impl Write) {
7    let s = read_all_unchecked(reader);
8    let mut scanner = Scanner::new(&s);
9    scan!(scanner, n, q, p: [usize]);
10    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
11    let tree = UndirectedSparseGraph::from_edges(n, edges);
12    let lca = tree.lca(0);
13    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
14        writeln!(writer, "{}", lca.lca(u, v)).ok();
15    }
16}
17
18#[verify::library_checker("lca")]
19pub fn lca_hld(reader: impl Read, mut writer: impl Write) {
20    let s = read_all_unchecked(reader);
21    let mut scanner = Scanner::new(&s);
22    scan!(scanner, n, q, p: [usize]);
23    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
24    let mut graph = UndirectedSparseGraph::from_edges(n, edges);
25    let hld = HeavyLightDecomposition::new(0, &mut graph);
26    for (u, v) in scanner.iter::<(usize, usize)>().take(q) {
27        writeln!(writer, "{}", hld.lca(u, v)).ok();
28    }
29}
crates/aizu_online_judge/src/grl/grl_4_b.rs (line 21)
15pub fn judge_grl_4_b(input: impl Read, _output: impl Read, result: impl Read) -> bool {
16    let (s_in, s_res) = (read_all_unchecked(input), read_all_unchecked(result));
17    let (mut scanner_in, mut scanner_res) = (Scanner::new(&s_in), Scanner::new(&s_res));
18    scan!(scanner_in, vs, es, edges: [(usize, usize)]);
19    let mut ord = vec![!0usize; vs];
20    let mut is_ac = true;
21    for (i, u) in scanner_res.iter::<usize>().take(vs).enumerate() {
22        is_ac &= ord[u] == !0usize;
23        ord[u] = i;
24    }
25    for (u, v) in edges.take(es) {
26        is_ac &= ord[u] < ord[v];
27    }
28    is_ac
29}

Trait Implementations§

Source§

impl<'a, I: Clone + Iterator<Item = &'a str>> Clone for Scanner<'a, I>

Source§

fn clone(&self) -> Scanner<'a, I>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, I: Debug + Iterator<Item = &'a str>> Debug for Scanner<'a, I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, I> Freeze for Scanner<'a, I>
where I: Freeze,

§

impl<'a, I> RefUnwindSafe for Scanner<'a, I>
where I: RefUnwindSafe,

§

impl<'a, I> Send for Scanner<'a, I>
where I: Send,

§

impl<'a, I> Sync for Scanner<'a, I>
where I: Sync,

§

impl<'a, I> Unpin for Scanner<'a, I>
where I: Unpin,

§

impl<'a, I> UnsafeUnpin for Scanner<'a, I>
where I: UnsafeUnpin,

§

impl<'a, I> UnwindSafe for Scanner<'a, I>
where I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.