fork download
  1. // yukicoder My Practice
  2. // author: Leonardone @ NEETSDKASU
  3. use std::io;
  4.  
  5. fn get_line() -> String {
  6. let mut input = String::new();
  7. io::stdin().read_line(&mut input).ok().expect("");
  8. return String::from(input.trim());
  9. }
  10.  
  11. fn get_words() -> Vec<String> {
  12. get_line()
  13. .split_whitespace()
  14. .map(String::from)
  15. .collect()
  16. }
  17.  
  18. fn get_integers() -> Vec<i32> {
  19. get_line()
  20. .split_whitespace()
  21. .map(|x| String::from(x).parse::<i32>().unwrap())
  22. .collect()
  23. }
  24.  
  25. fn main() {
  26.  
  27. let _ = get_line();
  28. let nums = get_integers();
  29.  
  30. let (ans, _) = nums
  31. .iter()
  32. .fold((0,0), |(ans, mx), &x|
  33. if x > mx { (ans, x) }
  34. else { if ans < x { (x, mx) } else { (ans, mx) } }
  35. );
  36.  
  37. println!("{}", ans);
  38. }
Success #stdin #stdout 0s 11000KB
stdin
5
3 1 4 2 5
stdout
2