Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs::File;
- use std::io::{Read, Write};
- use std::cmp::Reverse;
- use std::time::Instant;
- fn sort_file(input_path: &str, output_path: &str) -> std::io::Result<()> {
- let mut input_file = File::open(input_path)?;
- let mut contents: Vec<u8> = Vec::new();
- input_file.read_to_end(&mut contents)?;
- let space = ' ' as u8;
- let space_count = contents.iter().filter(|&&c| c == space).count();
- contents.retain(|&c| c != space);
- contents.sort();
- contents.extend(vec![space; space_count]);
- let mut output_file = File::create(output_path)?;
- output_file.write_all(&contents)?;
- Ok(())
- }
- fn main() {
- let start = Instant::now();
- sort_file("input.txt", "output.txt").unwrap();
- let end = Instant::now();
- println!("Rust Time {:?}", end - start);
- }
Advertisement
Add Comment
Please, Sign In to add comment