반응형
use std::env;
use std::fs::File;
use std::io::{self, BufRead, Write};
/*
* Complete the 'birthday' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY s
* 2. INTEGER d
* 3. INTEGER m
*/
fn birthday(s: &[i32], d: i32, m: i32) -> i32 {
let mut result = 0;
for i in 0..s.len() as i32 {
if i+m > s.len() as i32 {
break;
}
let mut temp = 0;
for j in 0..m as i32 {
temp += s[i as usize +j as usize];
}
if temp == d {
result += 1;
}
}
return result;
}
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 n = stdin_iterator.next().unwrap().unwrap().trim().parse::<i32>().unwrap();
let s: Vec<i32> = stdin_iterator.next().unwrap().unwrap()
.trim_end()
.split(' ')
.map(|s| s.to_string().parse::<i32>().unwrap())
.collect();
let first_multiple_input: Vec<String> = stdin_iterator.next().unwrap().unwrap()
.split(' ')
.map(|s| s.to_string())
.collect();
let d = first_multiple_input[0].trim().parse::<i32>().unwrap();
let m = first_multiple_input[1].trim().parse::<i32>().unwrap();
let result = birthday(&s, d, m);
writeln!(&mut fptr, "{}", result).ok();
}
반응형
'HackerRank' 카테고리의 다른 글
[HackerRank] Breaking the Records in Rust (0) | 2023.05.06 |
---|---|
[HackerRank] Number Line Jumps in Rust (0) | 2023.05.01 |
[HackerRank] Apple and Orange in Rust (0) | 2023.05.01 |
[HackerRank] Grading Students in Rust (0) | 2023.04.30 |