Pagini recente » Monitorul de evaluare | Cod sursa (job #2525421) | Cod sursa (job #850636) | Cod sursa (job #1081274) | Cod sursa (job #2685416)
use std::fs::File;
use std::path::Path;
use std::io::{self, BufRead};
use std::io::prelude::*;
fn main() {
println!("Hello, world!");
let path = Path::new("adunare.in");
let inf = File::open(path).expect("Error opening if");
let lines = io::BufReader::new(inf).lines();
let mut s = 0;
for line in lines {
let line = line.expect("Line read error");
println!("Read: {}", line);
let n: i32 = line.parse().expect("Number expected");
s+=n;
}
let mut of = File::create("adunare.out").expect("Error creating file");
of.write(s.to_string().as_bytes()).expect("Unable to write");
}