Skip to content

Instantly share code, notes, and snippets.

@Enet4
Created November 7, 2019 20:14
Show Gist options
  • Save Enet4/9b231e3f5c0db442344fdee491a599f1 to your computer and use it in GitHub Desktop.
Save Enet4/9b231e3f5c0db442344fdee491a599f1 to your computer and use it in GitHub Desktop.
// Best real time: 0.46s
use std::fs::File;
use std::io::{BufRead, BufReader};
fn is_blank(s: &str) -> bool {
s.chars().all(|c| c.is_whitespace())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("biggest.txt")?;
let mut file = BufReader::new(file);
let mut line = String::new();
let mut k = 0_u32;
while file.read_line(&mut line)? > 0 {
if is_blank(&line) {
k += 1;
}
line.clear();
}
println!("{}", k);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment