aboutsummaryrefslogtreecommitdiff
path: root/2022/01/common.rs
blob: 8ed8b49dbbede749058a07455e9cdab6cfbb2b33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pub fn get_elves_from_stdin() -> Vec<Vec<i64>> {
    let mut e = Vec::<Vec::<i64>>::new();
    e.push(Vec::<i64>::new());
    let mut line = String::new();
    loop {
        match std::io::stdin().read_line(&mut line).unwrap() {
            0 => break,
            1 => e.push(Vec::<i64>::new()),
            _ => {
                let n = line.trim().parse::<i64>().unwrap();
                let last = e.len() - 1;
                e[last].push(n);
            }
        }
        line.clear();
    }
    e
}

Generated with cgit - Back to sebastiano.tronto.net