Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. package com.company;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.ArrayList;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. Integer[] firstTeamCoordinates = GetTeamCoordinates();
  10. Integer[] secondTeamCoordinates = GetTeamCoordinates();
  11.  
  12. Boolean offside = CheckForOffsidePosition(firstTeamCoordinates, secondTeamCoordinates);
  13.  
  14. System.out.println(offside);
  15. }
  16.  
  17. public static Integer[] GetTeamCoordinates() {
  18. Scanner scanner = new Scanner(System.in);
  19.  
  20. String firstLine = scanner.nextLine();
  21.  
  22. Integer[] team = ParseInputToIntegerArray(firstLine);
  23.  
  24. return team;
  25. }
  26.  
  27. public static Integer[] ParseInputToIntegerArray(String input) {
  28. Integer[] result = new Integer[11];
  29. String[] inputToArray = input.split("\\s");
  30.  
  31. for (int i = 0; i < inputToArray.length; i++) {
  32. result[i] = Integer.parseInt(inputToArray[i]);
  33. }
  34.  
  35. return result;
  36. }
  37.  
  38. public static Boolean CheckForOffsidePosition(Integer[] firstTeam, Integer[] secondTeam) {
  39. int maxValueFirstTeam = FindMaxValueCoordinatesFirstTeam(firstTeam);
  40. int maxValueSecondTeam = FindMaxValueCoordinatesSecondTeam(secondTeam);
  41. int minValueFirstTeam = FindMinValueCoordinatesFirstTeam(firstTeam);
  42. int minValueSecondTeam = FindMinValueCoordinatesSecondTeam(secondTeam);
  43.  
  44. Boolean firstCase = TestFirstCase(maxValueFirstTeam, maxValueSecondTeam);
  45. Boolean secondCase = TestSecondCase(minValueSecondTeam, minValueFirstTeam);
  46.  
  47. if (firstCase) {
  48. return true;
  49. }
  50. else if (secondCase) {
  51. return true;
  52. }
  53.  
  54. return false;
  55. }
  56.  
  57. public static int FindMaxValueCoordinatesFirstTeam(Integer[] firstTeam) {
  58. int maxValue = Integer.MIN_VALUE;
  59.  
  60. for (int i = 0; i < firstTeam.length; i++) {
  61. if (firstTeam[i] > maxValue) {
  62. maxValue = firstTeam[i];
  63. }
  64. }
  65.  
  66. return maxValue;
  67. }
  68.  
  69. public static int FindMaxValueCoordinatesSecondTeam(Integer[] secondTeam) {
  70. int maxValue = Integer.MIN_VALUE;
  71.  
  72. for (int i = 0; i < secondTeam.length; i++) {
  73. if (secondTeam[i] > maxValue) {
  74. maxValue = secondTeam[i];
  75. }
  76. }
  77.  
  78. for (int i = 0; i < secondTeam.length; i++) {
  79. if (secondTeam[i] > maxValue) {
  80. maxValue = secondTeam[i];
  81. }
  82. }
  83.  
  84. return maxValue;
  85. }
  86.  
  87. public static int FindMinValueCoordinatesFirstTeam(Integer[] firstTeam) {
  88. int minValue = Integer.MAX_VALUE;
  89.  
  90. for (int i = 0; i < firstTeam.length; i++) {
  91. if (firstTeam[i] < minValue) {
  92. minValue = firstTeam[i];
  93. }
  94. }
  95.  
  96. Integer[] tempArray = ReplaceMinValue(firstTeam, minValue);
  97.  
  98. minValue = 101;
  99.  
  100. for (int i = 0; i < tempArray.length; i++) {
  101. if (tempArray[i] < minValue) {
  102. minValue = tempArray[i];
  103. }
  104. }
  105.  
  106. return minValue;
  107. }
  108.  
  109. public static int FindMinValueCoordinatesSecondTeam(Integer[] secondTeam) {
  110. int minValue = Integer.MAX_VALUE;
  111.  
  112. for (int i = 0; i < secondTeam.length; i++) {
  113. if (secondTeam[i] < minValue) {
  114. minValue = secondTeam[i];
  115. }
  116. }
  117.  
  118. return minValue;
  119. }
  120.  
  121. public static Boolean TestFirstCase(int maxValueFirstTeam, int maxValueSecondTeam) {
  122. if (maxValueFirstTeam > maxValueSecondTeam) {
  123. return true;
  124. }
  125.  
  126. return false;
  127. }
  128.  
  129. public static Boolean TestSecondCase(int minValueSecondTeam, int minValueFirstTeam) {
  130. if (minValueSecondTeam < minValueFirstTeam) {
  131. return true;
  132. }
  133.  
  134. return false;
  135. }
  136.  
  137. public static Integer[] ReplaceMinValue(Integer[] team, int value) {
  138. for (int i = 0; i < team.length; i++) {
  139. if (team[i] == value) {
  140. team[i] = Integer.MAX_VALUE;
  141. }
  142. }
  143.  
  144. return team;
  145. }
  146.  
  147. /* public static Integer[] ReplaceMaxValue(Integer[] team, int value) {
  148. for (int i = 0; i < team.length; i++) {
  149. if (team[i] == value) {
  150. team[i] = Integer.MIN_VALUE;
  151. }
  152. }
  153.  
  154. return team;
  155. } */
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement