mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-11-09 22:08:58 +01:00
feat(solutions): add cakes-swerc-2020-2021/rust/function
This commit is contained in:
parent
71e46d85fb
commit
431253da57
@ -15,8 +15,8 @@ make?
|
|||||||
|
|
||||||
### Input
|
### Input
|
||||||
|
|
||||||
- **Line 1:** Single integer `N` for the number of ingredients
|
- **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:
|
- **`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
|
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.
|
this ingredient you have in your kitchen.
|
||||||
|
|
||||||
|
7
challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/cakes-swerc-2020-2021/solutions/rust/function/Cargo.lock
generated
Normal file
@ -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"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "rust_application"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,3 @@
|
|||||||
|
# cakes-swerc-2020-2021/rust/function
|
||||||
|
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) on 4 January 2023.
|
@ -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<u32> = 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");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user