Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Created April 29, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanpuyue/b423a71013df21a6a41d3e97389657eb to your computer and use it in GitHub Desktop.
Save nanpuyue/b423a71013df21a6a41d3e97389657eb to your computer and use it in GitHub Desktop.
use std::env::args;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::str::FromStr;
fn main() {
let mut args = args();
if args.len() == 3 {
args.next();
let interval = u32::from_str(&args.next().unwrap()).unwrap();
let file = File::open(&args.next().unwrap()).unwrap();
let file = BufReader::new(file);
let mut end = 0;
for line in file.lines() {
if let Ok(s) = line {
let mut s = s.split_whitespace().collect::<Vec<&str>>();
let data = s[2];
s = s[0].split('-').collect();
let start = u32::from_str(s[0]).unwrap();
if start - end > interval {
print!("\n{}", data);
} else {
print!("{}", data);
}
end = u32::from_str(s[1]).unwrap();
}
}
}
println!();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment