update
This commit is contained in:
parent
8f063efbbe
commit
dcd876a636
26
src/main.rs
26
src/main.rs
|
@ -1,3 +1,29 @@
|
|||
use std::{fs, io::{self, BufRead, BufReader}};
|
||||
|
||||
fn main() {
|
||||
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
fn read_codes(code_file : &str) -> io::Result<Vec<u32>> {
|
||||
let file = fs::File::open(code_file)?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut codes = Vec::new();
|
||||
let mut line_count = 0;
|
||||
for line in reader.lines() {
|
||||
if let Ok(l) = line {
|
||||
let r_str = l.as_str();
|
||||
let code_vec : Vec<&str> = r_str.split(' ').collect();
|
||||
if code_vec.len() == 2 {
|
||||
let val1 : u32 = code_vec[0].parse().unwrap_or_default();
|
||||
let val2 : u32 = code_vec[1].parse().unwrap_or_default();
|
||||
codes.push(val1);
|
||||
codes.push(val2);
|
||||
} else {
|
||||
println!("code error at line {}.", line_count);
|
||||
}
|
||||
}
|
||||
line_count += 1;
|
||||
}
|
||||
Ok(codes)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue