mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-10-29 22:17:23 +01:00
feat(solutions): add is-palindrome/rust/function
This commit is contained in:
parent
257ab19f53
commit
e17156f0ab
7
challenges/is-palindrome/solutions/rust/function/Cargo.lock
generated
Normal file
7
challenges/is-palindrome/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 @@
|
|||||||
|
# is-palindrome/rust/function
|
||||||
|
|
||||||
|
Created by [@Divlo](https://github.com/Divlo) on 4 January 2023.
|
14
challenges/is-palindrome/solutions/rust/function/src/main.rs
Normal file
14
challenges/is-palindrome/solutions/rust/function/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use std::io;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut string = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut string)
|
||||||
|
.expect("Failed to read `stdin` line.");
|
||||||
|
let string = string.trim().replace(" ", "").to_lowercase();
|
||||||
|
let mut reverse: Vec<char> = string.chars().collect();
|
||||||
|
reverse.reverse();
|
||||||
|
let reverse: String = reverse.into_iter().collect();
|
||||||
|
let is_palindrome = reverse == string;
|
||||||
|
println!("{is_palindrome}");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user