2025-05-25 09:17:18 -05:00
|
|
|
use std::error::Error;
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::{self, BufReader, prelude::*};
|
|
|
|
|
use std::{env, fs};
|
|
|
|
|
|
|
|
|
|
fn parse_line(line: &str) -> Result<(i64, i64), Box<dyn Error>> {
|
|
|
|
|
// Split line on whitespace
|
|
|
|
|
// Expecting "88789 64926"
|
|
|
|
|
// Should end up with two string, if not something is wrong.
|
|
|
|
|
let split_line: Vec<_> = line
|
|
|
|
|
.splitn(2, char::is_whitespace)
|
|
|
|
|
.map(|elm| elm.trim())
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
// Parse and return our two elements
|
|
|
|
|
let first_element = split_line[0].parse::<i64>()?;
|
|
|
|
|
let second_element = split_line[1].parse::<i64>()?;
|
|
|
|
|
return Ok((first_element, second_element));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
// Handle command input
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
|
if args.len() != 2 {
|
|
|
|
|
panic!(
|
|
|
|
|
"{} must be run with a single argument of files name!",
|
|
|
|
|
&args[0]
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
let input_file_string = &args[1];
|
|
|
|
|
|
|
|
|
|
let input_file = File::open(input_file_string)?;
|
|
|
|
|
let input_reader = BufReader::new(input_file);
|
|
|
|
|
|
|
|
|
|
for (index, line) in input_reader.lines().enumerate() {
|
|
|
|
|
let line = line?;
|
|
|
|
|
let parsed_line = parse_line(&line)?;
|
|
|
|
|
println!("({},{})", parsed_line.0, parsed_line.1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(());
|
2025-05-25 08:15:48 -05:00
|
|
|
}
|