mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
fix: avoid usage of .unwrap
in Rust solutions
This commit is contained in:
parent
5b3048f305
commit
2386ea012d
@ -55,7 +55,9 @@ fn main() {
|
||||
row_ascii.clear();
|
||||
characters_ascii
|
||||
.get_mut(&characters[character_index])
|
||||
.unwrap()
|
||||
.expect(
|
||||
"Failed to get `characters[character_index]` key from `characters_ascii`.",
|
||||
)
|
||||
.push(row_ascii_value);
|
||||
character_index += 1;
|
||||
character_ascii_index = 0;
|
||||
@ -69,11 +71,20 @@ fn main() {
|
||||
let mut characters_needed: Vec<Vec<String>> = vec![];
|
||||
for (_, character) in text.char_indices() {
|
||||
let mut character = character.to_uppercase();
|
||||
let mut character = character.next().unwrap();
|
||||
let mut character = character
|
||||
.next()
|
||||
.expect("Failed to get `character.next()` value from `character.to_uppercase()`.");
|
||||
if !characters_ascii.contains_key(&character) {
|
||||
character = '?';
|
||||
}
|
||||
characters_needed.push(characters_ascii.get(&character).unwrap().clone());
|
||||
characters_needed.push(
|
||||
characters_ascii
|
||||
.get(&character)
|
||||
.expect(
|
||||
"Failed to get `characters_ascii.get(&character)` key from `characters_ascii`.",
|
||||
)
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let mut text_ascii = String::new();
|
||||
|
@ -22,12 +22,12 @@ fn main() {
|
||||
.get(0)
|
||||
.expect("Couldn't get `quantity_per_cake`.")
|
||||
.parse()
|
||||
.unwrap();
|
||||
.expect("Failed to convert `quantity_per_cake` as an `u32`.");
|
||||
let quantity_available: u32 = line_integers
|
||||
.get(1)
|
||||
.expect("Couldn't get `quantity_available`.")
|
||||
.parse()
|
||||
.unwrap();
|
||||
.expect("Failed to convert `quantity_available` as an `u32`.");
|
||||
|
||||
let cake_possible = quantity_available / quantity_per_cake;
|
||||
if let Some(value) = maximum_number_of_cake_possible {
|
||||
|
@ -3,6 +3,6 @@ use std::io::{self, BufRead};
|
||||
fn main() {
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
println!("Hello, {}!", line.unwrap());
|
||||
println!("Hello, {}!", line.expect("Failed to read `stdin` line."));
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,11 @@ fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
let line = line.expect("Failed to read `stdin` line.");
|
||||
let number: i64 = line
|
||||
.trim()
|
||||
.parse()
|
||||
.expect("Failed to convert `number` as an `i64`.");
|
||||
numbers.push(number);
|
||||
}
|
||||
bubble_sort(&mut numbers);
|
||||
|
@ -4,8 +4,11 @@ fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
let line = line.expect("Failed to read `stdin` line.");
|
||||
let number: i64 = line
|
||||
.trim()
|
||||
.parse()
|
||||
.expect("Failed to convert `number` as an `i64`.");
|
||||
numbers.push(number);
|
||||
}
|
||||
numbers.sort();
|
||||
|
@ -4,8 +4,11 @@ fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
let line = line.expect("Failed to read `stdin` line.");
|
||||
let number: i64 = line
|
||||
.trim()
|
||||
.parse()
|
||||
.expect("Failed to convert `number` as an `i64`.");
|
||||
numbers.push(number);
|
||||
}
|
||||
insertion_sort(&mut numbers);
|
||||
|
@ -4,8 +4,11 @@ fn main() {
|
||||
let mut numbers: Vec<i64> = Vec::new();
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
let number: i64 = line.trim().parse().unwrap();
|
||||
let line = line.expect("Failed to read `stdin` line.");
|
||||
let number: i64 = line
|
||||
.trim()
|
||||
.parse()
|
||||
.expect("Failed to convert `number` as an `i64`.");
|
||||
numbers.push(number);
|
||||
}
|
||||
merge_sort(&mut numbers);
|
||||
|
@ -3,6 +3,6 @@ use std::io::{self, BufRead};
|
||||
fn main() {
|
||||
let stdin = io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
println!("Hello, {}!", line.unwrap());
|
||||
println!("Hello, {}!", line.expect("Failed to read `stdin` line."));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user