mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(solutions): add acronyms/rust/function
This commit is contained in:
parent
29f8ac1da4
commit
31d1b65153
@ -10,7 +10,7 @@ Convert a given sentence to its acronym.
|
||||
|
||||
### Example 1
|
||||
|
||||
#### Input
|
||||
### Input
|
||||
|
||||
```txt
|
||||
Programming Challenges is really cool
|
||||
|
7
challenges/acronyms/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/acronyms/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"
|
6
challenges/acronyms/solutions/rust/function/Cargo.toml
Normal file
6
challenges/acronyms/solutions/rust/function/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust_application"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
3
challenges/acronyms/solutions/rust/function/README.md
Normal file
3
challenges/acronyms/solutions/rust/function/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# acronyms/rust/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 4 January 2023.
|
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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user