본문 바로가기

반응형

HackerRank

(5)
[HackerRank] Subarray Division in Rust 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; } l..
[HackerRank] Breaking the Records in Rust use std::env; use std::fs::File; use std::io::{self, BufRead, Write}; /* * Complete the 'breakingRecords' function below. * * The function is expected to return an INTEGER_ARRAY. * The function accepts INTEGER_ARRAY scores as parameter. */ fn breakingRecords(scores: &[i32]) -> Vec { let mut result = vec![0, 0]; let mut min = &scores[0]; let mut max = &scores[0]; for score in scores { if score > ..
[HackerRank] Number Line Jumps in Rust 단순 계산 문제임. 캥거루 1, 2가 다른 위치에서 다른 거리 만큼 점프를 하는데 점프 간격 시간은 같다. 캥거루 1, 2가 점프하기 시작한 후 동시에 같은 위치에서 점프하게 될 것인지 아닌지 여부를 구하는 문제. 조건 1 : a번째에 교차한다고 생각하면 더 먼 거리에서 시작한 캥거루의 점프 거리는 다른 캥거루보다 더 짧아야 한다.(v1>v2) 조건 2 : x2(더 먼 거리에서 시작한 캥거루의 시작 위치) + v2(더 먼 거리에서 시작한 캥거루의 점프 거리) * a번째점프 = x1(더 짧은 거리에서 시작한 캥거루의 시작 위치) + v1(더 짧은 거리에서 시작한 캥거루의 점프 거리) use std::env; use std::fs::File; use std::io::{self, BufRead, Write};..
[HackerRank] Apple and Orange in Rust vector의 각 element를 동일한 만큼 증가시킴 => map 메서드로 하나씩 처리한 뒤 collect 메서드로 결합. vector의 filter 메서드로 필터링 후 count 구할 수 있음. use std::io::{self, BufRead}; /* * Complete the 'countApplesAndOranges' function below. * * The function accepts following parameters: * 1. INTEGER s * 2. INTEGER t * 3. INTEGER a * 4. INTEGER b * 5. INTEGER_ARRAY apples * 6. INTEGER_ARRAY oranges */ fn countApplesAndOranges(s: i32, t: ..
[HackerRank] Grading Students in Rust use std::env; use std::fs::File; use std::io::{self, BufRead, Write}; /* * Complete the 'gradingStudents' function below. * * The function is expected to return an INTEGER_ARRAY. * The function accepts INTEGER_ARRAY grades as parameter. */ fn gradingStudents(grades: &[i32]) -> Vec { let mut results = Vec::new(); for i in 0..grades.len() { let grade = grades[i]; if grade % 5 >= 3 && grade > 37 { ..

반응형