1use std::fmt::{Debug, Display};
2use std::io;
3use std::str::FromStr;
4use text_io::read;
5
6pub fn read_vec<T>() -> Vec<T> where <T as FromStr>::Err: Debug, T: FromStr {
15 let mut input = String::new();
16 io::stdin().read_line(&mut input).unwrap();
17 input
18 .trim()
19 .split(' ')
20 .map(|x| x.to_string())
21 .filter(|x| !x.is_empty())
23 .collect::<Vec<String>>()
24 .iter()
25 .filter(|x| *x != " ")
26 .map(|x| match x.parse::<T>() {
27 Ok(x) => x,
28 Err(e) => panic!("Error parsing input: {:?}", e),
29 })
30 .collect::<Vec<T>>()
31}
32
33pub fn read<T>() -> T where <T as FromStr>::Err: Debug, T: FromStr + Display {
35 read!()
36}
37
38pub fn read_vec_len<T>(len: usize) -> Vec<T> where <T as FromStr>::Err: Debug, T: FromStr + Display {
47 let mut v = Vec::with_capacity(len);
48 for _ in 0..len {
49 let a = read!();
50 v.push(a);
51 }
52 v
53}
54#[macro_export]
57macro_rules! print_test_case {
58 ($case:expr, $($arg:tt)*) => {
59 println!("Case #{}: {}", $case, format_args!("{}", $($arg)*));
60 };
61}