format and u9
This commit is contained in:
parent
b8cfc80d1b
commit
f1b2a8c9ba
11 changed files with 114 additions and 84 deletions
116
src/main.rs
116
src/main.rs
|
@ -1,12 +1,4 @@
|
||||||
pub mod u1;
|
pub mod u1;
|
||||||
pub mod u2;
|
|
||||||
pub mod u3;
|
|
||||||
pub mod u4;
|
|
||||||
pub mod u5;
|
|
||||||
pub mod u6;
|
|
||||||
pub mod u7;
|
|
||||||
pub mod u8;
|
|
||||||
pub mod u9;
|
|
||||||
pub mod u10;
|
pub mod u10;
|
||||||
pub mod u11;
|
pub mod u11;
|
||||||
pub mod u12;
|
pub mod u12;
|
||||||
|
@ -17,6 +9,7 @@ pub mod u16;
|
||||||
pub mod u17;
|
pub mod u17;
|
||||||
pub mod u18;
|
pub mod u18;
|
||||||
pub mod u19;
|
pub mod u19;
|
||||||
|
pub mod u2;
|
||||||
pub mod u20;
|
pub mod u20;
|
||||||
pub mod u21;
|
pub mod u21;
|
||||||
pub mod u22;
|
pub mod u22;
|
||||||
|
@ -27,6 +20,7 @@ pub mod u26;
|
||||||
pub mod u27;
|
pub mod u27;
|
||||||
pub mod u28;
|
pub mod u28;
|
||||||
pub mod u29;
|
pub mod u29;
|
||||||
|
pub mod u3;
|
||||||
pub mod u30;
|
pub mod u30;
|
||||||
pub mod u31;
|
pub mod u31;
|
||||||
pub mod u32;
|
pub mod u32;
|
||||||
|
@ -37,6 +31,7 @@ pub mod u36;
|
||||||
pub mod u37;
|
pub mod u37;
|
||||||
pub mod u38;
|
pub mod u38;
|
||||||
pub mod u39;
|
pub mod u39;
|
||||||
|
pub mod u4;
|
||||||
pub mod u40;
|
pub mod u40;
|
||||||
pub mod u41;
|
pub mod u41;
|
||||||
pub mod u42;
|
pub mod u42;
|
||||||
|
@ -46,62 +41,67 @@ pub mod u45;
|
||||||
pub mod u46;
|
pub mod u46;
|
||||||
pub mod u47;
|
pub mod u47;
|
||||||
pub mod u48;
|
pub mod u48;
|
||||||
|
pub mod u5;
|
||||||
|
pub mod u6;
|
||||||
|
pub mod u7;
|
||||||
|
pub mod u8;
|
||||||
|
pub mod u9;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let ulohy = vec![
|
let ulohy = vec![
|
||||||
u1::main,
|
u1::main,
|
||||||
u2::main,
|
u2::main,
|
||||||
u3::main,
|
u3::main,
|
||||||
u4::main,
|
u4::main,
|
||||||
u5::main,
|
u5::main,
|
||||||
u6::main,
|
u6::main,
|
||||||
u7::main,
|
u7::main,
|
||||||
u8::main,
|
u8::main,
|
||||||
u9::main,
|
u9::main,
|
||||||
u10::main,
|
u10::main,
|
||||||
u11::main,
|
u11::main,
|
||||||
u12::main,
|
u12::main,
|
||||||
u13::main,
|
u13::main,
|
||||||
u14::main,
|
u14::main,
|
||||||
u15::main,
|
u15::main,
|
||||||
u16::main,
|
u16::main,
|
||||||
u17::main,
|
u17::main,
|
||||||
u18::main,
|
u18::main,
|
||||||
u19::main,
|
u19::main,
|
||||||
u20::main,
|
u20::main,
|
||||||
u21::main,
|
u21::main,
|
||||||
u22::main,
|
u22::main,
|
||||||
u23::main,
|
u23::main,
|
||||||
u24::main,
|
u24::main,
|
||||||
u25::main,
|
u25::main,
|
||||||
u26::main,
|
u26::main,
|
||||||
u27::main,
|
u27::main,
|
||||||
u28::main,
|
u28::main,
|
||||||
u29::main,
|
u29::main,
|
||||||
u30::main,
|
u30::main,
|
||||||
u31::main,
|
u31::main,
|
||||||
u32::main,
|
u32::main,
|
||||||
u33::main,
|
u33::main,
|
||||||
u34::main,
|
u34::main,
|
||||||
u35::main,
|
u35::main,
|
||||||
u36::main,
|
u36::main,
|
||||||
u37::main,
|
u37::main,
|
||||||
u38::main,
|
u38::main,
|
||||||
u39::main,
|
u39::main,
|
||||||
u40::main,
|
u40::main,
|
||||||
u41::main,
|
u41::main,
|
||||||
u42::main,
|
u42::main,
|
||||||
u43::main,
|
u43::main,
|
||||||
u44::main,
|
u44::main,
|
||||||
u45::main,
|
u45::main,
|
||||||
u46::main,
|
u46::main,
|
||||||
u47::main,
|
u47::main,
|
||||||
u48::main,
|
u48::main,
|
||||||
];
|
];
|
||||||
println!("Zadaj cislo ulohy:");
|
println!("Zadaj cislo ulohy:");
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
let i = input.trim().parse::<usize>().unwrap();
|
let i = input.trim().parse::<usize>().unwrap();
|
||||||
ulohy[i - 1]()
|
ulohy[i - 1]()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ pub fn main() {
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
println!("opacny retazec: {}", opacne_poradie(&input));
|
println!("opacny retazec: {}", opacne_poradie(&input));
|
||||||
input.clear();
|
input.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opacne_poradie(input: &String) -> String {
|
fn opacne_poradie(input: &String) -> String {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use std::ffi::CString;
|
|
||||||
use pyo3::ffi::c_str;
|
use pyo3::ffi::c_str;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
static code: &'static str = include_str!("u2.py");
|
static code: &'static str = include_str!("u2.py");
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
Python::with_gil(|py| {
|
Python::with_gil(|py| {
|
||||||
let c = CString::new(code.as_bytes()).unwrap();
|
let c = CString::new(code.as_bytes()).unwrap();
|
||||||
let activator = PyModule::from_code(py, c.as_c_str(), c_str!("main.py"), c_str!("main")).unwrap();
|
let activator =
|
||||||
|
PyModule::from_code(py, c.as_c_str(), c_str!("main.py"), c_str!("main")).unwrap();
|
||||||
activator.call_method("main", (), None).unwrap();
|
activator.call_method("main", (), None).unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
20
src/u3.rs
20
src/u3.rs
|
@ -1,18 +1,28 @@
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
let a: u128 = input.trim().parse().expect("Ocakavali sme prirodzene cislo");
|
let a: u128 = input
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.expect("Ocakavali sme prirodzene cislo");
|
||||||
input.clear();
|
input.clear();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
let b: u128 = input.trim().parse().expect("ocakavali sme prirodzene cislo");
|
let b: u128 = input
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.expect("ocakavali sme prirodzene cislo");
|
||||||
input.clear();
|
input.clear();
|
||||||
|
|
||||||
devidable(a, b);
|
devidable(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn devidable(a: u128, b: u128) {
|
fn devidable(a: u128, b: u128) {
|
||||||
for i in a..b+1 {
|
for i in a..b + 1 {
|
||||||
let digit_sum: u128 = i.to_string().chars().map(|c| c.to_digit(10).unwrap() as u128).sum();
|
let digit_sum: u128 = i
|
||||||
|
.to_string()
|
||||||
|
.chars()
|
||||||
|
.map(|c| c.to_digit(10).unwrap() as u128)
|
||||||
|
.sum();
|
||||||
if digit_sum % 3 == 0 {
|
if digit_sum % 3 == 0 {
|
||||||
println!("{}", i);
|
println!("{}", i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Poznámka: Palindróm je slovo, veta, číslo (všeobecne akákoľvek postupnos
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
|
|
||||||
println!("{}", palindrome(input.trim().to_string()));
|
println!("{}", palindrome(input.trim().to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,11 @@ pub fn main() {
|
||||||
|
|
||||||
let out = fun(a, b);
|
let out = fun(a, b);
|
||||||
println!("{}", out);
|
println!("{}", out);
|
||||||
|
|
||||||
let mut file = std::fs::OpenOptions::new().write(true).create(true).open("output.txt").unwrap();
|
let mut file = std::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open("output.txt")
|
||||||
|
.unwrap();
|
||||||
file.write_all(out.to_string().as_bytes()).unwrap();
|
file.write_all(out.to_string().as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use std::ffi::CString;
|
|
||||||
use pyo3::ffi::c_str;
|
use pyo3::ffi::c_str;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
static code: &'static str = include_str!("u6.py");
|
static code: &'static str = include_str!("u6.py");
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
Python::with_gil(|py| {
|
Python::with_gil(|py| {
|
||||||
let c = CString::new(code.as_bytes()).unwrap();
|
let c = CString::new(code.as_bytes()).unwrap();
|
||||||
let activator = PyModule::from_code(py, c.as_c_str(), c_str!("main.py"), c_str!("main")).unwrap();
|
let activator =
|
||||||
|
PyModule::from_code(py, c.as_c_str(), c_str!("main.py"), c_str!("main")).unwrap();
|
||||||
activator.call_method("main", (), None).unwrap();
|
activator.call_method("main", (), None).unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
12
src/u7.rs
12
src/u7.rs
|
@ -6,19 +6,19 @@ pub fn main() {
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
let b: i128 = input.trim().parse().unwrap();
|
let b: i128 = input.trim().parse().unwrap();
|
||||||
input.clear();
|
input.clear();
|
||||||
|
|
||||||
std::io::stdin().read_line(&mut input).unwrap();
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
let op = input.trim();
|
let op = input.trim();
|
||||||
|
|
||||||
match op {
|
match op {
|
||||||
"p" | "parne" => {
|
"p" | "parne" => {
|
||||||
let a = if a % 2 == 0 {a} else {a+1};
|
let a = if a % 2 == 0 { a } else { a + 1 };
|
||||||
for i in (a..=b).step_by(2) {
|
for i in (a..=b).step_by(2) {
|
||||||
print!("{} ", i);
|
print!("{} ", i);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"n" | "neparne" => {
|
"n" | "neparne" => {
|
||||||
let a = if a % 2 == 1 {a} else {a+1};
|
let a = if a % 2 == 1 { a } else { a + 1 };
|
||||||
for i in (a..=b).step_by(2) {
|
for i in (a..=b).step_by(2) {
|
||||||
print!("{} ", i);
|
print!("{} ", i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ pub fn main() {
|
||||||
let mut a3 = 0;
|
let mut a3 = 0;
|
||||||
let mut a4 = 0;
|
let mut a4 = 0;
|
||||||
let mut a5 = 0;
|
let mut a5 = 0;
|
||||||
|
|
||||||
for _ in 0..30 {
|
for _ in 0..30 {
|
||||||
let randnum = rand::random::<f32>();
|
let randnum = rand::random::<f32>();
|
||||||
let randnum = randnum * 5.0;
|
let randnum = randnum * 5.0;
|
||||||
let randnum = randnum as i32;
|
let randnum = randnum as i32;
|
||||||
|
|
||||||
match randnum {
|
match randnum {
|
||||||
0 => a1 += 1,
|
0 => a1 += 1,
|
||||||
1 => a2 += 1,
|
1 => a2 += 1,
|
||||||
|
@ -19,6 +19,6 @@ pub fn main() {
|
||||||
_ => panic!("Invalid number"),
|
_ => panic!("Invalid number"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("a1: {}, a2: {}, a3: {}, a4: {}, a5: {}", a1, a2, a3, a4, a5);
|
println!("a1: {}, a2: {}, a3: {}, a4: {}, a5: {}", a1, a2, a3, a4, a5);
|
||||||
}
|
}
|
||||||
|
|
17
src/u9.rs
17
src/u9.rs
|
@ -1 +1,16 @@
|
||||||
pub fn main() {}
|
pub fn main() {
|
||||||
|
let mut input = String::new();
|
||||||
|
std::io::stdin().read_line(&mut input).unwrap();
|
||||||
|
//i, í, y, ý, I, Í, Y, Ý
|
||||||
|
let input = input
|
||||||
|
.trim()
|
||||||
|
.replace("i", "_")
|
||||||
|
.replace("í", "_")
|
||||||
|
.replace("y", "_")
|
||||||
|
.replace("ý", "_")
|
||||||
|
.replace("I", "_")
|
||||||
|
.replace("Í", "_")
|
||||||
|
.replace("Y", "_")
|
||||||
|
.replace("Ý", "_");
|
||||||
|
println!("{}", input);
|
||||||
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ impl Vec2 {
|
||||||
pub fn new(x: f64, y: f64) -> Self {
|
pub fn new(x: f64, y: f64) -> Self {
|
||||||
Self { x, y }
|
Self { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_points(p1: Point, p2: Point) -> Self {
|
pub fn from_points(p1: Point, p2: Point) -> Self {
|
||||||
Self {
|
Self {
|
||||||
x: p2.x - p1.x,
|
x: p2.x - p1.x,
|
||||||
y: p2.y - p1.y,
|
y: p2.y - p1.y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> f64 {
|
pub fn size(&self) -> f64 {
|
||||||
(self.x.powi(2) + self.y.powi(2)).sqrt()
|
(self.x.powi(2) + self.y.powi(2)).sqrt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue