Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.List;
- import java.util.Scanner;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- Integer[] firstTeamCoordinates = GetTeamCoordinates();
- Integer[] secondTeamCoordinates = GetTeamCoordinates();
- Boolean offside = CheckForOffsidePosition(firstTeamCoordinates, secondTeamCoordinates);
- System.out.println(offside);
- }
- public static Integer[] GetTeamCoordinates() {
- Scanner scanner = new Scanner(System.in);
- String firstLine = scanner.nextLine();
- Integer[] team = ParseInputToIntegerArray(firstLine);
- return team;
- }
- public static Integer[] ParseInputToIntegerArray(String input) {
- Integer[] result = new Integer[11];
- String[] inputToArray = input.split("\\s");
- for (int i = 0; i < inputToArray.length; i++) {
- result[i] = Integer.parseInt(inputToArray[i]);
- }
- return result;
- }
- public static Boolean CheckForOffsidePosition(Integer[] firstTeam, Integer[] secondTeam) {
- int maxValueFirstTeam = FindMaxValueCoordinatesFirstTeam(firstTeam);
- int maxValueSecondTeam = FindMaxValueCoordinatesSecondTeam(secondTeam);
- int minValueFirstTeam = FindMinValueCoordinatesFirstTeam(firstTeam);
- int minValueSecondTeam = FindMinValueCoordinatesSecondTeam(secondTeam);
- Boolean firstCase = TestFirstCase(maxValueFirstTeam, maxValueSecondTeam);
- Boolean secondCase = TestSecondCase(minValueSecondTeam, minValueFirstTeam);
- if (firstCase) {
- return true;
- }
- else if (secondCase) {
- return true;
- }
- return false;
- }
- public static int FindMaxValueCoordinatesFirstTeam(Integer[] firstTeam) {
- int maxValue = Integer.MIN_VALUE;
- for (int i = 0; i < firstTeam.length; i++) {
- if (firstTeam[i] > maxValue) {
- maxValue = firstTeam[i];
- }
- }
- return maxValue;
- }
- public static int FindMaxValueCoordinatesSecondTeam(Integer[] secondTeam) {
- int maxValue = Integer.MIN_VALUE;
- for (int i = 0; i < secondTeam.length; i++) {
- if (secondTeam[i] > maxValue) {
- maxValue = secondTeam[i];
- }
- }
- for (int i = 0; i < secondTeam.length; i++) {
- if (secondTeam[i] > maxValue) {
- maxValue = secondTeam[i];
- }
- }
- return maxValue;
- }
- public static int FindMinValueCoordinatesFirstTeam(Integer[] firstTeam) {
- int minValue = Integer.MAX_VALUE;
- for (int i = 0; i < firstTeam.length; i++) {
- if (firstTeam[i] < minValue) {
- minValue = firstTeam[i];
- }
- }
- Integer[] tempArray = ReplaceMinValue(firstTeam, minValue);
- minValue = 101;
- for (int i = 0; i < tempArray.length; i++) {
- if (tempArray[i] < minValue) {
- minValue = tempArray[i];
- }
- }
- return minValue;
- }
- public static int FindMinValueCoordinatesSecondTeam(Integer[] secondTeam) {
- int minValue = Integer.MAX_VALUE;
- for (int i = 0; i < secondTeam.length; i++) {
- if (secondTeam[i] < minValue) {
- minValue = secondTeam[i];
- }
- }
- return minValue;
- }
- public static Boolean TestFirstCase(int maxValueFirstTeam, int maxValueSecondTeam) {
- if (maxValueFirstTeam > maxValueSecondTeam) {
- return true;
- }
- return false;
- }
- public static Boolean TestSecondCase(int minValueSecondTeam, int minValueFirstTeam) {
- if (minValueSecondTeam < minValueFirstTeam) {
- return true;
- }
- return false;
- }
- public static Integer[] ReplaceMinValue(Integer[] team, int value) {
- for (int i = 0; i < team.length; i++) {
- if (team[i] == value) {
- team[i] = Integer.MAX_VALUE;
- }
- }
- return team;
- }
- /* public static Integer[] ReplaceMaxValue(Integer[] team, int value) {
- for (int i = 0; i < team.length; i++) {
- if (team[i] == value) {
- team[i] = Integer.MIN_VALUE;
- }
- }
- return team;
- } */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement