aboutsummaryrefslogtreecommitdiff
path: root/2022/04/common.rs
blob: 92c32f1186722989b97ddfcc285a7321cc677a5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn get_ints(line: &str) -> ((i64, i64), (i64, i64)) {
    let i = line.find('-').unwrap();
    let j = line.find(',').unwrap();
    let k = line[j..].find('-').unwrap() + j;
    ((line[..i].parse().unwrap(), line[i+1..j].parse().unwrap()),
     (line[j+1..k].parse().unwrap(), line[k+1..line.len()-1].parse().unwrap()))
}

pub fn count<F: Fn((i64, i64), (i64, i64)) -> bool>(condition: F) -> i64 {
    let mut line = String::new();
    let mut sum = 0;
    while std::io::stdin().read_line(&mut line).unwrap() > 0 {
        let (a, b) = get_ints(&line);
        if condition(a, b) {
            sum += 1;
        }
        line.clear();
    }
    sum
}

Generated with cgit - Back to sebastiano.tronto.net