-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.rs
More file actions
38 lines (29 loc) · 885 Bytes
/
1.rs
File metadata and controls
38 lines (29 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::env;
use std::fs::File;
use std::io::{self, BufRead, Write};
/*
* Complete the 'simpleArraySum' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY ar as parameter.
*/
fn simpleArraySum(ar: &[i32]) -> i32 {
let mut sum = 0;
for i in ar {
sum += i;
}
sum
}
fn main() {
let stdin = io::stdin();
let mut stdin_iterator = stdin.lock().lines();
let mut fptr = File::create(env::var("OUTPUT_PATH").unwrap()).unwrap();
let _ar_count = stdin_iterator.next().unwrap().unwrap().trim().parse::<i32>().unwrap();
let ar: Vec<i32> = stdin_iterator.next().unwrap().unwrap()
.trim_end()
.split(' ')
.map(|s| s.to_string().parse::<i32>().unwrap())
.collect();
let result = simpleArraySum(&ar);
writeln!(&mut fptr, "{}", result).ok();
}