Created
November 7, 2019 20:14
-
-
Save Enet4/9b231e3f5c0db442344fdee491a599f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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