reto01
This commit is contained in:
8
ejercicios/reto01/Cargo.toml
Normal file
8
ejercicios/reto01/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
58
ejercicios/reto01/src/main.rs
Normal file
58
ejercicios/reto01/src/main.rs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Escribe un programa que reciba un texto y transforme lenguaje natural a
|
||||||
|
* "lenguaje hacker" (conocido realmente como "leet" o "1337"). Este lenguaje
|
||||||
|
* se caracteriza por sustituir caracteres alfanuméricos.
|
||||||
|
* - Utiliza esta tabla (https://www.gamehouse.com/blog/leet-speak-cheat-sheet/)
|
||||||
|
* con el alfabeto y los números en "leet".
|
||||||
|
* (Usa la primera opción de cada transformación. Por ejemplo "4" para la "a")
|
||||||
|
*/
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let alphabet = String::from_utf8((b'A'..=b'Z').chain(b'0'..=b'9').collect()).unwrap();
|
||||||
|
println!("{}", alphabet);
|
||||||
|
let respuesta = [
|
||||||
|
"4",
|
||||||
|
"l3",
|
||||||
|
"[",
|
||||||
|
")",
|
||||||
|
"3",
|
||||||
|
"|=",
|
||||||
|
"&",
|
||||||
|
"#",
|
||||||
|
"1",
|
||||||
|
",_|",
|
||||||
|
">|",
|
||||||
|
"1",
|
||||||
|
"^^",
|
||||||
|
"^",
|
||||||
|
"0",
|
||||||
|
"|*",
|
||||||
|
"(_,)",
|
||||||
|
"l2",
|
||||||
|
"hu",
|
||||||
|
"gg",
|
||||||
|
"pesadooooooooo",
|
||||||
|
"0",
|
||||||
|
"yy",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
];
|
||||||
|
let vecalphabet: Vec<_> = alphabet.split("").collect();
|
||||||
|
let texto = String::from("wtf hijo de puta hay que decirlo mas").to_uppercase();
|
||||||
|
let vectexto: Vec<_> = texto.split("").collect();
|
||||||
|
let mut textfinal = "".to_string();
|
||||||
|
for item in vectexto {
|
||||||
|
if alphabet.contains(item) {
|
||||||
|
let index = vecalphabet
|
||||||
|
.iter()
|
||||||
|
.position(|&r| r == item.to_string())
|
||||||
|
.unwrap();
|
||||||
|
if index != 0 {
|
||||||
|
//println!("es->{}", respuesta[index]);
|
||||||
|
textfinal += &respuesta[index].to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{}", textfinal)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user