Question

Using Java, implement:

(2) Team Selection Coach Sean Miller is looking for an optimal way for his basketball team selection. Initially he has to shortlist and remove some of the players before final selection. So, he called all the players and told them to stand side by side in a single line. Now he started removing a player if the player Px has someone py in his right who is taller than him (h< h Write a program for coach Sean Miller to help him eliminate the players under his chosen criteria using Linked List. As he is in hurry, you must make sure the solution is optimal Input Format: Read input from a file in2.txt. First line contains number of test cases. Second line contains the jersey number of the players. Third line contains heights of the players in centimeters. Output Format: Write Sample Input: output in console. Print jersey numbers of the remaining players. 1234567 177 175 165 172 161 170 164 Sample Output: 12467

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.util.*;

class player{
    public int jersy_no;
    public int height;
}

public class DemoChoose{

     public static void main(String[] args){

       try {
          LinkedList<player> list = new LinkedList<player>();
          File file = new File("in2.txt");
          Scanner sc = new Scanner(file);
          String line="";

          int n = Integer.parseInt(sc.nextLine());
          for (int i = 0; i<n; i++){
             line = sc.nextLine();
             String[] words = line.split(" ");
             for(int j = 0; j<words.length; j++){
                
                 player p = new player();
                 p.jersy_no = Integer.parseInt(words[j]);
                 list.add(p);
             }
            
             line = sc.nextLine();
             words = line.split(" ");
             for(int j = 0; j<words.length; j++){
                 list.get(j).height = Integer.parseInt(words[j]);
             }
            
          }
         
          for (int i = 0; i<list.size(); i++){
             if (i+1 < list.size()){
                if (list.get(i).height > list.get(i+1).height)
                   System.out.print(list.get(i).jersy_no + " ");
             }
             else {
                  System.out.println(list.get(i).jersy_no);
             }
          }
          System.out.println();
         
        } catch (Exception e){
                 e.printStackTrace();
        }

     }
}

Add a comment
Know the answer?
Add Answer to:
Using Java, implement: (2) Team Selection Coach Sean Miller is looking for an optimal way for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT