Question
(in java) Create a program named RunningGroups.java and implements the following static method: public static int runningGroups(String inputFileName) throws IOException this method returns the number
(in java) Create a program named RunningGroups.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: There are N (1 <= N <= 200,000) people running on a single-lane 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. Input data: The 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. SAMPLE INPUT: 5 0 1 1 2 2 3 3 2 6 1 The number of running group: 2
Given files:
***** 1.in :
5 0 1 1 2 2 3 3 2 6 1
****** 10.in :
100000 40027 1969556 57418 162078844 76039 9925023 87012 79020 100614 10937078 112348 241378 114652 110785 126086 30938813 126525 108896348 129244 34514107 134603 24087650 142966 59399355 147922 106850175
1.in - 10.in files were given similar to the one above
***** RunningGroups.txt
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; } } //*1.in *2.in *3.in *4.in *5.in *6.in *7.in *8.in *9.in *10.in
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