1
1
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:
Divlo
2023-01-04 07:50:35 +01:00
parent 29f8ac1da4
commit 31d1b65153
5 changed files with 38 additions and 1 deletions

View 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));
}