From b3600502f761e7f71a160b257a722472afc53150 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 27 Mar 2023 07:33:31 +0400 Subject: [PATCH] Add code --- 112A.rs | 24 ++++++++++++++++++++++++ 263A.rs | 17 +++++++++++++++++ 339A.rs | 11 +++++++++++ 4A.rs | 18 ++++++++++++++++++ 50A.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 112A.rs create mode 100644 263A.rs create mode 100644 339A.rs create mode 100644 4A.rs create mode 100644 50A.rs diff --git a/112A.rs b/112A.rs new file mode 100644 index 0000000..5041d4a --- /dev/null +++ b/112A.rs @@ -0,0 +1,24 @@ +use std::cmp::Ordering; +use std::io::{self, BufRead, BufReader, Write}; + +fn main() { + let mut stdin = io::stdin(); + let mut stdout = io::stdout(); + + let lines: Vec = + BufReader::new(stdin) + .lines() + .map(|line| line.unwrap().to_lowercase()) + .collect(); + + let line1 = lines[0].as_str(); + let line2 = lines[1].as_str(); + + let result = match line1.cmp(line2) { + Ordering::Less => -1, + Ordering::Equal => 0, + Ordering::Greater => 1, + }; + + stdout.write_all(format!("{}\n", result).as_ref()).unwrap(); +} diff --git a/263A.rs b/263A.rs new file mode 100644 index 0000000..3db66f9 --- /dev/null +++ b/263A.rs @@ -0,0 +1,17 @@ +use std::io::{self, BufRead}; + +fn main() { + let matrix: Vec> = + io::BufReader::new(io::stdin()) + .lines() + .map(|item| { + item.unwrap().split_whitespace().position(|item| item == "1") + .and_then(|item| Some(item as i32)) + }) + .collect(); + + let vertical_ops = (2 - (matrix.iter().position(|item| *item != None).unwrap() as i32)).abs(); + let horizontal_ops = (2 - matrix.iter().find(|item| **item != None).unwrap().unwrap()).abs(); + + println!("{}", vertical_ops + horizontal_ops); +} diff --git a/339A.rs b/339A.rs new file mode 100644 index 0000000..72a3f9c --- /dev/null +++ b/339A.rs @@ -0,0 +1,11 @@ +use std::io; + +fn main() { + let mut buf = String::new(); + io::stdin().read_line(&mut buf).unwrap(); + + let mut numbers: Vec = buf.trim_end().split('+').map(|item| item.to_string()).collect(); + numbers.sort(); + + println!("{}", numbers.join("+")); +} diff --git a/4A.rs b/4A.rs new file mode 100644 index 0000000..f64568d --- /dev/null +++ b/4A.rs @@ -0,0 +1,18 @@ +use std::io::{self, Read, Write}; + +fn main() { + let mut stdin = io::stdin(); + let mut stdout = io::stdout(); + + let mut weight_string = String::new(); + stdin.read_to_string(&mut weight_string).unwrap(); + + let weight = weight_string.trim_end().parse::().unwrap(); + + if weight % 2 == 0 && weight != 2 { + stdout.write_all(b"YES\n").unwrap(); + } + else { + stdout.write_all(b"NO\n").unwrap(); + } +} diff --git a/50A.rs b/50A.rs new file mode 100644 index 0000000..f24ceab --- /dev/null +++ b/50A.rs @@ -0,0 +1,26 @@ +use std::io::{self, Read, Write}; + +fn main() { + let mut stdin = io::stdin(); + let mut stdout = io::stdout(); + + let mut input = String::new(); + stdin.read_to_string(&mut input).unwrap(); + + let mut inputs = input.split_whitespace(); + let input1 = inputs.next().unwrap(); + let input2 = inputs.next().unwrap(); + + let width = input1.parse::().unwrap(); + let height: i32 = input2.parse().unwrap(); + + let result = + if width % 2 == 0 || height % 2 == 0 { + width * height / 2 + } + else { + (width * height - 1) / 2 + }; + + stdout.write_all(format!("{}\n", result).as_ref()).unwrap(); +}