This commit is contained in:
DavidOnTop 2025-04-02 09:16:24 +02:00
parent 5788b5df57
commit 8891926fec
Signed by: DavidOnTop
GPG key ID: 8D3E9A75E3E13D89
7 changed files with 145 additions and 5 deletions

21
cisla.txt Normal file
View file

@ -0,0 +1,21 @@
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
3
3
3
3
3
1.75

1
doplnovacka.txt Normal file
View file

@ -0,0 +1 @@
_orasjgls_rgahrosl_ghseor_aehr_lsgdrhgos_ehr

View file

@ -1 +1,15 @@
pub fn main() {} 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")
}
}

View file

@ -1 +1,14 @@
pub fn main() {} 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}");
}

View file

@ -1 +1,61 @@
pub fn main() {} 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 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)
}
}
impl Error for LengthError {}
fn pocet_chyb(i1: String, i2: String) -> Result<usize, LengthError> {
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
}
fn generuj_retazec(i1: String) -> String {
i1.chars().map(|c| {
match c {
'A' => 'T',
'T' => 'A',
'C' => 'G',
'G' => 'C',
_ => ' ',
}
}).collect()
}

View file

@ -1 +1,18 @@
pub fn main() {} 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::<f64>() / 20f64;
println!("priemer: {avg}");
cisla.push(avg);
file.write_all(cisla.iter().map(|f| f.to_string()).collect::<Vec<String>>().join("\n").as_bytes()).unwrap()
}

View file

@ -1 +1,15 @@
pub fn main() {} 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);
}