diff --git a/challenges/cakes-swerc-2020-2021/README.md b/challenges/cakes-swerc-2020-2021/README.md index 7d275bb..3d80dd3 100644 --- a/challenges/cakes-swerc-2020-2021/README.md +++ b/challenges/cakes-swerc-2020-2021/README.md @@ -15,8 +15,8 @@ make? ### Input -- **Line 1:** Single integer `N` for the number of ingredients -- **`n` next lines:**, One for each ingredient. Each of these lines contains two positive integers: +- **Line 1:** Single integer `N` for the number of ingredients. +- **`N` next lines:** One for each ingredient. Each of these lines contains two positive integers: the first one is the required quantity of this ingredient per cake, the second one is the quantity of this ingredient you have in your kitchen. diff --git a/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.lock b/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.lock new file mode 100644 index 0000000..c8ae10e --- /dev/null +++ b/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust_application" +version = "1.0.0" diff --git a/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.toml b/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.toml new file mode 100644 index 0000000..a119ace --- /dev/null +++ b/challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rust_application" +version = "1.0.0" +edition = "2021" + +[dependencies] diff --git a/challenges/cakes-swerc-2020-2021/solutions/rust/function/README.md b/challenges/cakes-swerc-2020-2021/solutions/rust/function/README.md new file mode 100644 index 0000000..9989c0a --- /dev/null +++ b/challenges/cakes-swerc-2020-2021/solutions/rust/function/README.md @@ -0,0 +1,3 @@ +# cakes-swerc-2020-2021/rust/function + +Created by [@Divlo](https://github.com/Divlo) on 4 January 2023. diff --git a/challenges/cakes-swerc-2020-2021/solutions/rust/function/src/main.rs b/challenges/cakes-swerc-2020-2021/solutions/rust/function/src/main.rs new file mode 100644 index 0000000..5f9a902 --- /dev/null +++ b/challenges/cakes-swerc-2020-2021/solutions/rust/function/src/main.rs @@ -0,0 +1,46 @@ +use std::io; + +fn main() { + let mut number_of_ingredients = String::new(); + io::stdin() + .read_line(&mut number_of_ingredients) + .expect("Failed to read `stdin` line."); + let number_of_ingredients: usize = number_of_ingredients + .trim() + .parse() + .expect("Failed to convert `number_of_ingredients` as an `usize`."); + + let mut maximum_number_of_cake_possible: Option = None; + + for _ in 0..number_of_ingredients { + let mut line = String::new(); + io::stdin() + .read_line(&mut line) + .expect("Failed to read `stdin` line."); + let line_integers: Vec<&str> = line.trim().split_whitespace().collect(); + let quantity_per_cake: u32 = line_integers + .get(0) + .expect("Couldn't get `quantity_per_cake`.") + .parse() + .unwrap(); + let quantity_available: u32 = line_integers + .get(1) + .expect("Couldn't get `quantity_available`.") + .parse() + .unwrap(); + + let cake_possible = quantity_available / quantity_per_cake; + if let Some(value) = maximum_number_of_cake_possible { + if cake_possible < value { + maximum_number_of_cake_possible = Some(cake_possible); + } + } else { + maximum_number_of_cake_possible = Some(cake_possible); + } + } + if let Some(value) = maximum_number_of_cake_possible { + println!("{value}"); + } else { + println!("0"); + } +}