Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Criteria For Solution: -PLEASE USE THE EXAMPLE CODE PROVIDED BELOW -PLEASE SOLVE USING JAVA -WRITE A FULLY ANSWERED, OPTIMIZED, AND DETAILED CODE WITH COMMENTS AND

Criteria For Solution: -PLEASE USE THE EXAMPLE CODE PROVIDED BELOW -PLEASE SOLVE USING JAVA -WRITE A FULLY ANSWERED, OPTIMIZED, AND DETAILED CODE WITH COMMENTS AND SCREENSHOTS -WRITE A FULLY EXPLAINED APPROACH ON HOW TO SOLVE IT AND WHY THAT APPROACH -TIME/SPACE COMPLEXITY ALONG WITH THE WHY -ALL TEST CASES BELOW MUST PASS Java Example Code:

import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {

/* * Complete the 'getEventsOrder' function below. * * The function is expected to return a STRING_ARRAY. * The function accepts following parameters: * 1. STRING team1 * 2. STRING team2 * 3. STRING_ARRAY events1 * 4. STRING_ARRAY events2 */

public static List getEventsOrder(String team1, String team2, List events1, List events2) { // Write your code here

}

}

public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

String team1 = bufferedReader.readLine();

String team2 = bufferedReader.readLine();

int events1Count = Integer.parseInt(bufferedReader.readLine().trim());

List events1 = IntStream.range(0, events1Count).mapToObj(i -> { try { return bufferedReader.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } }) .collect(toList());

int events2Count = Integer.parseInt(bufferedReader.readLine().trim());

List events2 = IntStream.range(0, events2Count).mapToObj(i -> { try { return bufferedReader.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } }) .collect(toList());

List result = Result.getEventsOrder(team1, team2, events1, events2);

bufferedWriter.write( result.stream() .collect(joining(" ")) + " " );

bufferedReader.close(); bufferedWriter.close(); } } image text in transcribedimage text in transcribed image text in transcribedTest Case #1: ABC CBA 2 Mo Sa 45+2 Y A 13 G 2 D 23 S F Z 46 G Test Case #2: nolh uzrdrrc slcpx 3 inmuucz jzbkica 70 Y ton wfnt 10 S imuucz jzbkica ecya kqvqy 20 S fkfk fuiyb senmofw 3 mysior pqfcz bxlnpn 49 G mysior pqfcz bxlnpn 18 G enc otagavd oevfg 68 Y

4. Game Events Two teams were playing a football (soccer) match and the record of events for each team is available. There are 4 possible events, Goal (G), Yellow Card (Y), Red Card (R) and Substitution (S). The first three events (G, Y, R) are represented as player-name time event-name whereas the last event (S) is represented as player-name time event-name second-player-name. The time is represented in minutes from the start of the game. A football game is divided into two halves of 45 minutes each, and sometimes a little extra time is given at the end of each half, which is represented in the time as time+extra-time. So, there can be two types of times, for example, 32 and 45+2. The extra time is always considered to have occurred before the events of the next half, so, 45+2 happened earlier than 46. Merge the events for each team into a single game event with teams name in front and sorted by time and event in order of G, Y, R, S. In the case of the same event happening at the same time, output should be sorted lexicographically based on teams name and players name. Take for example, the first team team1 = "EDC" with events recorded as events 1 = ['Name1 12 G','FirstName LastName 43 Y'] and second team team2 = "CDE" with events recorded as events2 = ['Name3 45+1 S SubName', 'Name4 46 G'), then the chronological order of events is given by: EDC Name1 12G EDC FirstName LastName 43 Y CDE Name3 45+1 S SubName CDE Name4 46 G Function Description Complete the function getEventsOrder in the editor below. The function must return an array of strings. getEventsOrder has the following parameter(s): team1: a string, the name of the first team team2: a string, the name of the second team events1[events 1[0],...events 1 [n-1]]: an array of strings that describe the events of the first team events2[events2[0]....events2[n-1]]: an array of strings that describe the events of the second team Constraints Os length of events1, events2 = 20 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions