Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fmt::Debug;
- use std::io;
- use std::iter::FromIterator;
- use std::num::ParseIntError;
- use std::str::{FromStr, SplitWhitespace};
- use std::cmp::{max, min};
- #[inline]
- #[allow(dead_code)]
- fn input<T: FromStr<Err = ParseIntError> + Debug>() -> T {
- let mut input = String::new();
- io::stdin().read_line(&mut input).unwrap();
- input.trim().parse().unwrap()
- }
- #[inline]
- #[allow(dead_code)]
- fn input_container<T, C>() -> C
- where
- T: FromStr<Err = ParseIntError> + Debug,
- C: FromIterator<T>,
- {
- let mut input = String::new();
- io::stdin().read_line(&mut input).unwrap();
- input
- .split_whitespace()
- .map(|x| x.parse::<T>().unwrap())
- .collect::<C>()
- }
- #[inline]
- #[allow(dead_code)]
- fn input_pair<F, S>() -> (F, S)
- where
- F: FromStr<Err = ParseIntError> + Debug,
- S: FromStr<Err = ParseIntError> + Debug,
- {
- let mut input = String::new();
- io::stdin().read_line(&mut input).unwrap();
- let mut input = input.split_whitespace();
- (
- input.next().unwrap().parse().unwrap(),
- input.next().unwrap().parse().unwrap(),
- )
- }
- #[inline]
- #[allow(dead_code)]
- fn input_it(mut input: &mut String) -> SplitWhitespace<'_> {
- io::stdin().read_line(&mut input).unwrap();
- input.split_whitespace()
- }
- fn main() {
- let a = input::<i32>();
- let b = input::<i32>();
- let c = input::<i32>();
- let d = input::<i32>();
- let max = max(a, b);
- let min = min(a, b);
- println!("{}",
- if c == max {
- if d == 1 { 1 } else { min }
- } else if c == min {
- if d == 1 { 1 } else { max }
- } else if c > min {
- if d == 1 { max - c + 1 } else { c - 1 }
- } else {
- if d == 1 { min - c + 1 } else { max - min + c }
- }
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement