Cod sursa(job #2685416)

Utilizator paulbPaul B paulb Data 16 decembrie 2020 20:50:30
Problema A+B Scor 100
Compilator rs Status done
Runda Arhiva de probleme Marime 0.63 kb
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");
}