From 5e7b7a2c01187969400a0b90d05639b244da5df8 Mon Sep 17 00:00:00 2001 From: davidontop Date: Thu, 10 Apr 2025 14:31:27 +0200 Subject: [PATCH] fmt --- src/u10.rs | 9 ++++--- src/u11.rs | 12 ++++++++- src/u13.rs | 9 ++++--- src/u14.rs | 15 ++++++++--- src/u3.rs | 2 +- src/u31.rs | 16 ++++++++---- src/u32.rs | 10 +++---- src/u33.rs | 34 ++++++++++++------------ src/u34.rs | 22 ++++++++-------- src/u35.rs | 20 +++++++------- src/u36.rs | 77 +++++++++++++++++++++++++++--------------------------- src/u37.rs | 39 ++++++++++++++++++--------- src/u38.rs | 25 +++++++++++------- src/u39.rs | 45 ++++++++++++++++--------------- src/u40.rs | 10 +++---- src/u41.rs | 50 ++++++++++++++++++----------------- src/u42.rs | 22 ++++++++-------- src/u46.rs | 44 +++++++++++++++++++++---------- src/u47.rs | 10 ++++--- src/u48.rs | 46 ++++++++++++++++++++------------ 20 files changed, 298 insertions(+), 219 deletions(-) diff --git a/src/u10.rs b/src/u10.rs index 0fe1c8e..cb3811f 100644 --- a/src/u10.rs +++ b/src/u10.rs @@ -4,12 +4,15 @@ pub fn main() { v.push(rand::random::() * 40.0 - 20.0); } v.sort_by(|a, b| a.partial_cmp(b).unwrap()); - + println!("{:?}", v); - + let mut input = String::new(); println!("zadajte cislo"); std::io::stdin().read_line(&mut input).unwrap(); let input: f32 = input.trim().parse().unwrap(); - println!("{}", v.iter().position(|x| *x == input).unwrap_or(usize::MAX)) + println!( + "{}", + v.iter().position(|x| *x == input).unwrap_or(usize::MAX) + ) } diff --git a/src/u11.rs b/src/u11.rs index d712c7c..7619097 100644 --- a/src/u11.rs +++ b/src/u11.rs @@ -8,6 +8,16 @@ pub fn main() { panic!("Invalid input"); } let mut input = input.to_lowercase(); - input = input.chars().enumerate().map(|(i, c)| if i == 0 { c.to_uppercase().next().unwrap() } else { c }).collect(); + input = input + .chars() + .enumerate() + .map(|(i, c)| { + if i == 0 { + c.to_uppercase().next().unwrap() + } else { + c + } + }) + .collect(); println!("{}", input); } diff --git a/src/u13.rs b/src/u13.rs index b3bd264..30cc1d6 100644 --- a/src/u13.rs +++ b/src/u13.rs @@ -4,18 +4,19 @@ pub fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); match input.trim() { - "1." | "1" | "mtokm" => read_and_convert(|u| {u * 1.609344}), - "2." | "2" | "kmtom" => read_and_convert(|u| {u / 1.609344}), + "1." | "1" | "mtokm" => read_and_convert(|u| u * 1.609344), + "2." | "2" | "kmtom" => read_and_convert(|u| u / 1.609344), _ => {} } } fn read_and_convert(tom: F) -where F: Fn(f64) -> f64 +where + F: Fn(f64) -> f64, { println!("zadaj udaj"); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let unit: f64 = input.trim().parse().unwrap(); println!("{}", tom(unit)); -} \ No newline at end of file +} diff --git a/src/u14.rs b/src/u14.rs index 10bb0a9..d2f4c03 100644 --- a/src/u14.rs +++ b/src/u14.rs @@ -7,8 +7,17 @@ pub fn main() { teploty.push(rand.gen::() * 40.0 - 20.0); } println!("teploty: {:?}", teploty); - println!("najnizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::min).unwrap()); - println!("najvizsia {}", teploty.iter().map(|e| e.clone()).reduce(f64::max).unwrap()); + println!( + "najnizsia {}", + teploty.iter().map(|e| e.clone()).reduce(f64::min).unwrap() + ); + println!( + "najvizsia {}", + teploty.iter().map(|e| e.clone()).reduce(f64::max).unwrap() + ); println!("priemer {}", teploty.iter().sum::() / 20.0); - println!("pocet nulovych teplot: {}", teploty.iter().find(|e| **e == 0.0).iter().count()) + println!( + "pocet nulovych teplot: {}", + teploty.iter().find(|e| **e == 0.0).iter().count() + ) } diff --git a/src/u3.rs b/src/u3.rs index 06aef62..430fcef 100644 --- a/src/u3.rs +++ b/src/u3.rs @@ -14,7 +14,7 @@ pub fn main() { .parse() .expect("ocakavali sme prirodzene cislo"); input.clear(); - + println!("Cisla delitelne tromi v intervale od {} do {}", a, b); devidable(a, b); diff --git a/src/u31.rs b/src/u31.rs index 4c2e70c..3789746 100644 --- a/src/u31.rs +++ b/src/u31.rs @@ -2,9 +2,15 @@ static DNA: &'static str = "AACTATTTCGGGGGGCGAGCCCTCATCGTCTCTTCTGCGGATGACTCAACAC static DNAMUT: &'static str = "AACTATGTCGCGAGGCGAGCTCTCATCGTCTCGTCTGCGGATGACTCCACACGCTAGCGACGTGAAGTCGAATCCGTCGATGGTTATAAATCAGAGACTCAGAGTGCTGTCTGGAGCGTGAATCTAACGGTACGTATCTCGATAGCTCGGTCGCTTTTCGCACTCCGCGAAAGTTCGTACCGCTCATACACTAGGTTGCGAAGCCTATGCTGATATATGAATCCACACTAGAGCAGTGCTCTTAAGAATCGCAGTTGTAAATACTTAATACTCCAATCGGCTTTTACGTGCACCACCGCGCGCGGCTGACAAGGGTCTCACATCGGGAAACAAGACAGTTCCGGGCTGGAAGTAGCGCCGGCTAAGGAAGACGCCTGGTACGGCAGGACTATGAAACCAGTACAAAGGCAACATCCTCACTTGGGTGAACGGAAACGCAGTATTATGGTTACTTCCTGGATACGTGAAACATATCCCATGGTAGTCCTTAGACTTGGGAGTCTATCACCCCTAGGGCCCATATCTGGAGATAGACGCCAGGTTGAATCCGTATTTGGAGGTACGATGGAACAGTCTGGGTGGGACGTGCTTCATTTATACCCTGCGCAGGCTGGACCGAGGACCGCAAGGTGCGGCGGTGCACAAGCAATTGACAACTAACCACCGTGTATTCATTATGGTACCAGGAACTTTAAGCCGAGTCAATGAAGCTCGCATTACAGTGTGTACCGCATCTTGCCGTTACTCACACACTGTGATCCACCACAAGTCAAGCCATTGCCTCTCTGACACGCCGTAAGAATTAATATGTAAACTTTGCGCGGGTTGACTGCGATCCGTTCAGTCTCGTCCGAGGGCACAATCCTATTCCCATTTGTATGTTCAGCTAACTTCTACCCATCCTCTGAAGTTAAGTAGGTCGTGAGATGCCATGGAGGCTCTCGTTCATCCCGTGGGACATCAAGCTTCCCCTTGATAAAGCACCCCGCTCGGGTGTAAA"; pub fn main() { - DNA.chars().zip(DNAMUT.chars()).enumerate().for_each(|(i, (d, m))| { - if (d != m) { - println!("Mutacia nastala na {} pozicii povodna {d}, nova {m}", i + 1) - } - }) + DNA.chars() + .zip(DNAMUT.chars()) + .enumerate() + .for_each(|(i, (d, m))| { + if (d != m) { + println!( + "Mutacia nastala na {} pozicii povodna {d}, nova {m}", + i + 1 + ) + } + }) } diff --git a/src/u32.rs b/src/u32.rs index 126fe52..c8289d1 100644 --- a/src/u32.rs +++ b/src/u32.rs @@ -1,7 +1,7 @@ pub fn main() { - for i in 1..5 { - for j in 0..10 { - println!("{i}{j}{i}") - } - } + for i in 1..5 { + for j in 0..10 { + println!("{i}{j}{i}") + } + } } diff --git a/src/u33.rs b/src/u33.rs index 251ac6a..290a6df 100644 --- a/src/u33.rs +++ b/src/u33.rs @@ -1,19 +1,19 @@ pub fn main() { - println!("Zadaj cislo a znacku (F/C)"); - let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap(); - let mut input = input.trim().to_string(); - let unit = input.remove(input.len() - 1); - let num: f64 = input.parse().expect("Neda sa retazec premenit na cislo"); - match unit { - 'C' | 'c' => { - println!("{}F", num * 1.8 + 32.0) - } - 'F' | 'f' => { - println!("{}C", (num - 32.0)/1.8) - } - _ => { - println!("nepodporovana znacka") - } - } + println!("Zadaj cislo a znacku (F/C)"); + let mut input = String::new(); + std::io::stdin().read_line(&mut input).unwrap(); + let mut input = input.trim().to_string(); + let unit = input.remove(input.len() - 1); + let num: f64 = input.parse().expect("Neda sa retazec premenit na cislo"); + match unit { + 'C' | 'c' => { + println!("{}F", num * 1.8 + 32.0) + } + 'F' | 'f' => { + println!("{}C", (num - 32.0) / 1.8) + } + _ => { + println!("nepodporovana znacka") + } + } } diff --git a/src/u34.rs b/src/u34.rs index b1591bd..6139cca 100644 --- a/src/u34.rs +++ b/src/u34.rs @@ -1,15 +1,15 @@ static SAM: &str = "aeiyou"; pub fn main() { - let mut input = String::new(); - println!("Zadaj slovo"); - std::io::stdin().read_line(&mut input).unwrap(); - let mut input = input.trim().to_string(); - if SAM.contains(input.chars().next().expect("Slovo musi mat aspon 1 znak")) { - println!("{input}way") - } else { - let c = input.chars().next().unwrap(); - input.replace_range(0..1, ""); - println!("{input}{c}ay") - } + let mut input = String::new(); + println!("Zadaj slovo"); + std::io::stdin().read_line(&mut input).unwrap(); + let mut input = input.trim().to_string(); + if SAM.contains(input.chars().next().expect("Slovo musi mat aspon 1 znak")) { + println!("{input}way") + } else { + let c = input.chars().next().unwrap(); + input.replace_range(0..1, ""); + println!("{input}{c}ay") + } } diff --git a/src/u35.rs b/src/u35.rs index 260940a..48c43af 100644 --- a/src/u35.rs +++ b/src/u35.rs @@ -1,14 +1,14 @@ static SAM: &str = "aeiyouáéíóúý"; pub fn main() { - let mut input = String::new(); - println!("Zadaj vetu"); - std::io::stdin().read_line(&mut input).unwrap(); - let mut input = input.trim().to_string(); - - for c in SAM.chars() { - input = input.replace(c, "_"); - } - - println!("{input}"); + let mut input = String::new(); + println!("Zadaj vetu"); + std::io::stdin().read_line(&mut input).unwrap(); + let mut input = input.trim().to_string(); + + for c in SAM.chars() { + input = input.replace(c, "_"); + } + + println!("{input}"); } diff --git a/src/u36.rs b/src/u36.rs index 1bfbeea..80787dc 100644 --- a/src/u36.rs +++ b/src/u36.rs @@ -2,60 +2,59 @@ use std::error::Error; use std::fmt::{Debug, Display, Formatter}; pub fn main() { - let mut input1 = String::new(); - println!("Zadaj 1 retazec DNA"); - std::io::stdin().read_line(&mut input1).unwrap(); - let input1 = input1.trim().to_uppercase().to_string(); - let mut input2 = String::new(); - println!("Zadaj 2 complementarny retazec DNA"); - std::io::stdin().read_line(&mut input2).unwrap(); - let input2 = input2.trim().to_uppercase().to_string(); + let mut input1 = String::new(); + println!("Zadaj 1 retazec DNA"); + std::io::stdin().read_line(&mut input1).unwrap(); + let input1 = input1.trim().to_uppercase().to_string(); + let mut input2 = String::new(); + println!("Zadaj 2 complementarny retazec DNA"); + std::io::stdin().read_line(&mut input2).unwrap(); + let input2 = input2.trim().to_uppercase().to_string(); - let n_chyb = pocet_chyb(input1.clone(), input2.clone()).unwrap(); - println!("Pocet chyb: {n_chyb}"); - println!("Percento chyb: {}", percento_chyb(input1.clone(), input2)); - println!("Complementarny retazec: {}", generuj_retazec(input1)); + let n_chyb = pocet_chyb(input1.clone(), input2.clone()).unwrap(); + println!("Pocet chyb: {n_chyb}"); + println!("Percento chyb: {}", percento_chyb(input1.clone(), input2)); + println!("Complementarny retazec: {}", generuj_retazec(input1)); } #[derive(Default, Debug)] struct LengthError(String); impl Display for LengthError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(&self.0, f) - } + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } } impl Error for LengthError {} - fn pocet_chyb(i1: String, i2: String) -> Result { - if i1.len() != i2.len() { - return Err(LengthError("Dna a complementarne dna niesu rovnako dlhe".to_string())) - } - let mut n: usize = 0; - i1.chars().zip(i2.chars()).for_each(|cp| { - match cp { - ('A', 'T') | ('T', 'A') | ('C', 'G') | ('G', 'C') => (), - _ => n += 1 - } - }); - Ok(n) + if i1.len() != i2.len() { + return Err(LengthError( + "Dna a complementarne dna niesu rovnako dlhe".to_string(), + )); + } + let mut n: usize = 0; + i1.chars().zip(i2.chars()).for_each(|cp| match cp { + ('A', 'T') | ('T', 'A') | ('C', 'G') | ('G', 'C') => (), + _ => n += 1, + }); + Ok(n) } fn percento_chyb(i1: String, i2: String) -> f64 { - let n_chyb = pocet_chyb(i1.clone(), i2).unwrap(); - (n_chyb as f64 / i1.len() as f64) * 100f64 + let n_chyb = pocet_chyb(i1.clone(), i2).unwrap(); + (n_chyb as f64 / i1.len() as f64) * 100f64 } fn generuj_retazec(i1: String) -> String { - i1.chars().map(|c| { - match c { - 'A' => 'T', - 'T' => 'A', - 'C' => 'G', - 'G' => 'C', - _ => ' ', - } - }).collect() -} \ No newline at end of file + i1.chars() + .map(|c| match c { + 'A' => 'T', + 'T' => 'A', + 'C' => 'G', + 'G' => 'C', + _ => ' ', + }) + .collect() +} diff --git a/src/u37.rs b/src/u37.rs index dd35288..766c725 100644 --- a/src/u37.rs +++ b/src/u37.rs @@ -2,17 +2,30 @@ use std::fs::OpenOptions; use std::io::Write; pub fn main() { - let mut file = OpenOptions::new().create(true).truncate(true).write(true).open("./cisla.txt").unwrap(); - let mut cisla = Vec::with_capacity(21); - for i in 0..20 { - let mut input = String::new(); - println!("Zadaj cislo {} z 20", i + 1); - std::io::stdin().read_line(&mut input).unwrap(); - let inp: f64 = input.trim().parse().unwrap(); - cisla.push(inp); - } - let avg = cisla.iter().sum::() / 20f64; - println!("priemer: {avg}"); - cisla.push(avg); - file.write_all(cisla.iter().map(|f| f.to_string()).collect::>().join("\n").as_bytes()).unwrap() + let mut file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open("./cisla.txt") + .unwrap(); + let mut cisla = Vec::with_capacity(21); + for i in 0..20 { + let mut input = String::new(); + println!("Zadaj cislo {} z 20", i + 1); + std::io::stdin().read_line(&mut input).unwrap(); + let inp: f64 = input.trim().parse().unwrap(); + cisla.push(inp); + } + let avg = cisla.iter().sum::() / 20f64; + println!("priemer: {avg}"); + cisla.push(avg); + file.write_all( + cisla + .iter() + .map(|f| f.to_string()) + .collect::>() + .join("\n") + .as_bytes(), + ) + .unwrap() } diff --git a/src/u38.rs b/src/u38.rs index aeb6aaf..af78207 100644 --- a/src/u38.rs +++ b/src/u38.rs @@ -2,14 +2,19 @@ use std::fs::OpenOptions; use std::io::Write; pub fn main() { - let mut input = String::new(); - println!("Zadaj diktat"); - std::io::stdin().read_line(&mut input).unwrap(); - let input = input.trim().to_string(); - let povodny_pocet = input.clone().chars().filter(|c| *c == '_').count(); - let diktat = input.replace(['i', 'í', 'y', 'ý'], "_"); - let mut file = OpenOptions::new().create(true).truncate(true).write(true).open("./doplnovacka.txt").unwrap(); - file.write_all(diktat.clone().as_bytes()).unwrap(); - let max = diktat.chars().filter(|c| *c == '_').count() - povodny_pocet; - println!("Max pocet chyb: {}", max); + let mut input = String::new(); + println!("Zadaj diktat"); + std::io::stdin().read_line(&mut input).unwrap(); + let input = input.trim().to_string(); + let povodny_pocet = input.clone().chars().filter(|c| *c == '_').count(); + let diktat = input.replace(['i', 'í', 'y', 'ý'], "_"); + let mut file = OpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open("./doplnovacka.txt") + .unwrap(); + file.write_all(diktat.clone().as_bytes()).unwrap(); + let max = diktat.chars().filter(|c| *c == '_').count() - povodny_pocet; + println!("Max pocet chyb: {}", max); } diff --git a/src/u39.rs b/src/u39.rs index 9f5473c..770d690 100644 --- a/src/u39.rs +++ b/src/u39.rs @@ -1,28 +1,27 @@ pub fn main() { - let mut input1 = String::new(); - std::io::stdin().read_line(&mut input1).unwrap(); - let input1 = input1.trim().parse().unwrap(); - let mut input2 = String::new(); - std::io::stdin().read_line(&mut input2).unwrap(); - let input2 = input2.trim().parse().unwrap(); - - let res = max(input1, input2); - - if let Some(res) = res { - println!("{res}") - } else { - println!("rovnake") - } + let mut input1 = String::new(); + std::io::stdin().read_line(&mut input1).unwrap(); + let input1 = input1.trim().parse().unwrap(); + let mut input2 = String::new(); + std::io::stdin().read_line(&mut input2).unwrap(); + let input2 = input2.trim().parse().unwrap(); + + let res = max(input1, input2); + + if let Some(res) = res { + println!("{res}") + } else { + println!("rovnake") + } } pub fn max(i1: i32, i2: i32) -> Option { - let res = (i1.to_string().len(), i2.to_string().len()); - if res.0 == res.1 { - None - } else if res.0 > res.1 { - Some(i1) - } else { - Some(i2) - } + let res = (i1.to_string().len(), i2.to_string().len()); + if res.0 == res.1 { + None + } else if res.0 > res.1 { + Some(i1) + } else { + Some(i2) + } } - diff --git a/src/u40.rs b/src/u40.rs index 7380869..6d99368 100644 --- a/src/u40.rs +++ b/src/u40.rs @@ -1,7 +1,7 @@ pub fn main() { - let mut sutaziaci = vec![("aoeu", 21), ("htns", 25), ("pyfg", 16)]; - sutaziaci.sort_by(|s, l| {s.1.cmp(&l.1)}); - sutaziaci.iter().for_each(|n| { - println!("{} {}", n.0, n.1); - }) + let mut sutaziaci = vec![("aoeu", 21), ("htns", 25), ("pyfg", 16)]; + sutaziaci.sort_by(|s, l| s.1.cmp(&l.1)); + sutaziaci.iter().for_each(|n| { + println!("{} {}", n.0, n.1); + }) } diff --git a/src/u41.rs b/src/u41.rs index 1930e00..a3c14aa 100644 --- a/src/u41.rs +++ b/src/u41.rs @@ -1,27 +1,29 @@ pub fn main() { - println!("Prve cislo: "); - let mut num = String::new(); - std::io::stdin().read_line(&mut num).unwrap(); - let num: f64 = num.trim().parse().unwrap(); + println!("Prve cislo: "); + let mut num = String::new(); + std::io::stdin().read_line(&mut num).unwrap(); + let num: f64 = num.trim().parse().unwrap(); - println!("operator: "); - let mut operand = String::new(); - std::io::stdin().read_line(&mut operand).unwrap(); - let operand = operand.trim().to_string(); + println!("operator: "); + let mut operand = String::new(); + std::io::stdin().read_line(&mut operand).unwrap(); + let operand = operand.trim().to_string(); - println!("Druhe cislo: "); - let mut num1 = String::new(); - std::io::stdin().read_line(&mut num1).unwrap(); - let num1: f64 = num1.trim().parse().unwrap(); - - let operator = match operand.as_str() { - "+" => {|c1: f64, c2: f64| {c1 + c2}} - "-" => {|c1: f64, c2: f64| {c1 - c2}} - "*" => {|c1: f64, c2: f64| {c1 * c2}} - "/" => {|c1: f64, c2: f64| {c1 / c2}} - _ => {panic!("Zly operator")} - }; - - let result = operator(num, num1); - println!("Vysledok {result}"); -} \ No newline at end of file + println!("Druhe cislo: "); + let mut num1 = String::new(); + std::io::stdin().read_line(&mut num1).unwrap(); + let num1: f64 = num1.trim().parse().unwrap(); + + let operator = match operand.as_str() { + "+" => |c1: f64, c2: f64| c1 + c2, + "-" => |c1: f64, c2: f64| c1 - c2, + "*" => |c1: f64, c2: f64| c1 * c2, + "/" => |c1: f64, c2: f64| c1 / c2, + _ => { + panic!("Zly operator") + } + }; + + let result = operator(num, num1); + println!("Vysledok {result}"); +} diff --git a/src/u42.rs b/src/u42.rs index 74c4120..8501991 100644 --- a/src/u42.rs +++ b/src/u42.rs @@ -1,13 +1,13 @@ pub fn main() { - println!("Zaklad"); - let mut inp = String::new(); - std::io::stdin().read_line(&mut inp).unwrap(); - let inp: f64 = inp.trim().parse().unwrap(); - - println!("mocnitel: "); - let mut n = String::new(); - std::io::stdin().read_line(&mut n).unwrap(); - let n: f64 = n.trim().parse().unwrap(); - - println!("vysledok: {}", inp.powf(n)) + println!("Zaklad"); + let mut inp = String::new(); + std::io::stdin().read_line(&mut inp).unwrap(); + let inp: f64 = inp.trim().parse().unwrap(); + + println!("mocnitel: "); + let mut n = String::new(); + std::io::stdin().read_line(&mut n).unwrap(); + let n: f64 = n.trim().parse().unwrap(); + + println!("vysledok: {}", inp.powf(n)) } diff --git a/src/u46.rs b/src/u46.rs index 7d2ae36..a12ae47 100644 --- a/src/u46.rs +++ b/src/u46.rs @@ -1,16 +1,32 @@ pub fn main() { - println!("pocet ziakov: "); - let mut num = String::new(); - std::io::stdin().read_line(&mut num).unwrap(); - let num: usize = num.trim().parse().unwrap(); - - let mut ziaci = Vec::with_capacity(num); - for i in 0..num { - println!("Zadaj ziaka {i}, vo formate: meno priezvisko, trieda, znamka znamka znamka znamka znamka"); - let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap(); - let input = input.trim().split(",").map(|s| {s.trim().to_string()}).collect::>(); - ziaci.push((input[0].clone(), input[1].clone(), input[2].clone().split(" ").map(|z| {z.parse::().unwrap()}).collect::>())); - } - let ziaci = ziaci.iter().map(|z| (z, z.2.iter().sum::() as f64 / 5.0)).collect::>().sort_by(|z, e| {z.1.partial_cmp(&e.1)}); + println!("pocet ziakov: "); + let mut num = String::new(); + std::io::stdin().read_line(&mut num).unwrap(); + let num: usize = num.trim().parse().unwrap(); + + let mut ziaci = Vec::with_capacity(num); + for i in 0..num { + println!("Zadaj ziaka {i}, vo formate: meno priezvisko, trieda, znamka znamka znamka znamka znamka"); + let mut input = String::new(); + std::io::stdin().read_line(&mut input).unwrap(); + let input = input + .trim() + .split(",") + .map(|s| s.trim().to_string()) + .collect::>(); + ziaci.push(( + input[0].clone(), + input[1].clone(), + input[2] + .clone() + .split(" ") + .map(|z| z.parse::().unwrap()) + .collect::>(), + )); + } + let ziaci = ziaci + .iter() + .map(|z| (z, z.2.iter().sum::() as f64 / 5.0)) + .collect::>() + .sort_by(|z, e| z.1.partial_cmp(&e.1).unwrap()); } diff --git a/src/u47.rs b/src/u47.rs index 92322ba..58713d8 100644 --- a/src/u47.rs +++ b/src/u47.rs @@ -1,9 +1,11 @@ pub fn main() { - rec(7) + rec(7) } fn rec(num: i32) { - if num >= 1000 {return;} - println!("num: {num}"); - rec(num + 7) + if num >= 1000 { + return; + } + println!("num: {num}"); + rec(num + 7) } diff --git a/src/u48.rs b/src/u48.rs index 01eab0b..18e914c 100644 --- a/src/u48.rs +++ b/src/u48.rs @@ -1,20 +1,34 @@ pub fn main() { - let ziaci = ["Horák Marek","Gajdáč Tibor","Velická Barbora","Malík Peter","Malíková Diana"]; + let ziaci = [ + "Horák Marek", + "Gajdáč Tibor", + "Velická Barbora", + "Malík Peter", + "Malíková Diana", + ]; - let hodiny= [15,0,0,75,34]; + let hodiny = [15, 0, 0, 75, 34]; - println!("Vsetky vymeskane hodiniy: {}", hodiny.iter().sum::()); - println!("Priemerny pocet vymeskanych hodin: {}", hodiny.iter().sum::() as f64 / hodiny.len() as f64); - let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| {z.1.cmp(&e.1)}); - if let Some(najhorsi) = najhorsi { - println!("Najhorsiu dochadzku ma: {} s dochadzkou {}", najhorsi.0, najhorsi.1) - } else { - println!("Nepodarilo sa najst najhorsieho") - } - let s0 = ziaci.iter().zip(hodiny).filter(|e| {e.1 == 0}).collect::>(); - println!("pocet ziakou ktori mozu mat pochvalu: {}", s0.len()); - println!("Ziaci na pochvalu"); - s0.iter().for_each(|e| { - println!(" {}", e.0) - }); + println!("Vsetky vymeskane hodiniy: {}", hodiny.iter().sum::()); + println!( + "Priemerny pocet vymeskanych hodin: {}", + hodiny.iter().sum::() as f64 / hodiny.len() as f64 + ); + let najhorsi = ziaci.iter().zip(hodiny).max_by(|z, e| z.1.cmp(&e.1)); + if let Some(najhorsi) = najhorsi { + println!( + "Najhorsiu dochadzku ma: {} s dochadzkou {}", + najhorsi.0, najhorsi.1 + ) + } else { + println!("Nepodarilo sa najst najhorsieho") + } + let s0 = ziaci + .iter() + .zip(hodiny) + .filter(|e| e.1 == 0) + .collect::>(); + println!("pocet ziakou ktori mozu mat pochvalu: {}", s0.len()); + println!("Ziaci na pochvalu"); + s0.iter().for_each(|e| println!(" {}", e.0)); }