organizado en carpetas
This commit is contained in:
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mapeo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
println!("-- Ejercicio 1");
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert('A', 10);
|
||||
mapa.insert('B', 20);
|
||||
|
||||
let idx = 'A';
|
||||
let mapeo = mapa.get(&idx);
|
||||
println!("{:?}", mapeo);
|
||||
|
||||
println!("-- Ejercicio 2");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
let idx = String::from("primero");
|
||||
let mapeo = mapa.get(&idx);
|
||||
println!("{:?}", mapeo);
|
||||
|
||||
println!("-- Ejercicio 3");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 4");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
mapa.insert(String::from("primero"), 30);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 5");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
mapa.entry(String::from("primero")).or_insert(30);
|
||||
mapa.entry(String::from("tercero")).or_insert(40);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 6");
|
||||
|
||||
let texto = "hola mundo maravilloso mundo";
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
for palabra in texto.split_whitespace() {
|
||||
let contar = mapa.entry(palabra).or_insert(0);
|
||||
*contar += 1;
|
||||
}
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user