Pagini recente » Cod sursa (job #1258092) | Cod sursa (job #1903252) | Cod sursa (job #1586886) | Cod sursa (job #1986345) | Cod sursa (job #2775816)
use std::fs;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Error;
use std::path::Path;
fn main() {
let path = Path::new("adunare.in");
let a = get_line_at(&path, 0).unwrap();
let b = get_line_at(&path, 1).unwrap();
let int_a = a.parse::<i32>().unwrap();
let int_b = b.parse::<i32>().unwrap();
let sum = sum(int_a, int_b);
fs::write("adunare.out", sum.to_string()).expect("Unable to write file");
}
fn get_line_at(path: &Path, line_num: usize) -> Result<String, Error> {
// Read that exact line from the file
let file = File::open(path).expect("File not found or cannot be opened");
let content = BufReader::new(&file);
let mut lines = content.lines();
lines.nth(line_num).expect("No line found at that position")
}
fn sum(a: i32, b: i32) -> i32 {
return a + b
}