Question
Create a program named RunnerGroups.java and implements the following static method: public static int runningGroups(String inputFileName) throws IOException this method returns the number of running
Create a program named RunnerGroups.java and implements the following static method:
public static int runningGroups(String inputFileName) throws IOException
this method returns the number of running groups
public static int[] runningGroups(String[] inputFileNames) throws IOException
it returns an int array, each element in the array represents the number of running groups for its corresponding input file.
Then test your program. Here is the problem description:
ane track. Assuming the track is infinitely long. Each person starts at a distinct position on the track, and runners may run at different speeds. Runners cannot pass each other because there is only one lane in the track. When a faster runner catches up to another person, he or she must slow down to avoid running into the other people, becoming part of the same running group. Eventually, no more runners will run into each other and all runners will run in a group (it is possible there is only one runner in a group). Peter wonders how many running groups will be formed eventually. Peter has been working on this problem for more than 3 hours and feels frustrated at this point. Please help this poor guy find this number.
There are N (1 <= N <= 200,000) people running on a single-
inpu data:
I
e first line of the input file contains the integer N, followed by N lines containing the starting position(>=0) and speed (>0) of each runner. Both numbers(starting position and speed) are at most 1 billion. All runners start at different positions, and these(starting position) will be given in increasing order in the input.
T hSAMPLE INPUT: 5 0 1 1 2 2 3 3 2 6 1
FILES PROVIDED
import java.io.*;
public class RunningGroups{
public static void main(String[] args) throws IOException{
//TO DO
}
public static int runningGroups(String fileName) throws IOException{
//TO DO
return 0;
}
public static int[] runningGroups(String[] fileNames) throws IOException{
//TO DO
return null;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started