mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
feat(solutions): add acronyms/rust/function
This commit is contained in:
21
challenges/acronyms/solutions/rust/function/src/main.rs
Normal file
21
challenges/acronyms/solutions/rust/function/src/main.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use std::io;
|
||||
|
||||
pub fn get_acronym(sentence: &str) -> String {
|
||||
let words = sentence.replace("\"", "");
|
||||
let words = words.split_whitespace();
|
||||
let mut acronym = String::new();
|
||||
for word in words {
|
||||
if let Some(character) = word.to_uppercase().chars().next() {
|
||||
acronym.push(character);
|
||||
}
|
||||
}
|
||||
acronym
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Failed to read `stdin` line.");
|
||||
println!("{}", get_acronym(&input));
|
||||
}
|
Reference in New Issue
Block a user