fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. class Player{
  10. int playerId;
  11. String playerName;
  12. int runs;
  13. String playerType;
  14. String matchType;
  15.  
  16. public int getPlayerId(){
  17. return playerId;
  18. }
  19.  
  20. public String getPlayerName(){
  21. return playerName;
  22. }
  23.  
  24. public int getRuns(){
  25. return runs;
  26. }
  27.  
  28. public String getPlayerType(){
  29. return playerType;
  30. }
  31.  
  32. public String getMatchType(){
  33. return matchType;
  34. }
  35.  
  36. Player(int playerId, String playerName, int runs, String playerType, String matchType){
  37. this.playerId = playerId;
  38. this.playerName = playerName;
  39. this.runs = runs;
  40. this.playerType = playerType;
  41. this.matchType = matchType;
  42. }
  43. }
  44. class Ideone
  45. {
  46.  
  47. public static ArrayList<Player> fun1(Player[] ls, String s){
  48. ArrayList<Player> pl = new ArrayList<>();
  49. for(Player p : ls){
  50. if(p.getPlayerType().equalsIgnoreCase(s)){
  51. pl.add(p);
  52. }
  53. }
  54. if(pl.size() == 0){
  55. return null;
  56. }
  57.  
  58. Collections.sort(pl, (a,b) -> a.getRuns() - b.getRuns());
  59. return pl;
  60. }
  61.  
  62. public static ArrayList<Player> fun2(Player[] ls, String s){
  63. ArrayList<Player> pl = new ArrayList<>();
  64. for(Player p : ls){
  65. if(p.getMatchType().equalsIgnoreCase(s)){
  66. pl.add(p);
  67. }
  68. }
  69. if(pl.size() == 0){
  70. return null;
  71. }
  72. Collections.sort(pl, (a,b) -> a.getRuns() - b.getRuns());
  73. return pl;
  74. }
  75. public static void main (String[] args) throws java.lang.Exception
  76. {
  77. // your code goes here
  78. Scanner sc = new Scanner(System.in);
  79. Player[] players = new Player[4];
  80. for(int i = 0; i < 4; i++){
  81. int a = sc.nextInt();
  82. sc.nextLine();
  83. String b = sc.nextLine();
  84. int c = sc.nextInt();
  85. sc.nextLine();
  86. String d = sc.nextLine();
  87. String e = sc.nextLine();
  88. players[i] = new Player(a,b,c,d,e);
  89. }
  90. String T1 = sc.nextLine();
  91. String T2 = sc.nextLine();
  92.  
  93. ArrayList<Player> P1 = fun1(players, T1);
  94.  
  95. if(P1 == null){
  96. System.out.println("No Such Player");
  97. }else{
  98. Player pp = P1.get(0);
  99. System.out.println(pp.getRuns());
  100. }
  101. ArrayList<Player> P2 = fun2(players, T2);
  102.  
  103. if(P2 == null){
  104. System.out.println("No Player with given matchType");
  105. }else{
  106. for(Player pp : P2){
  107. int id = pp.getPlayerId();
  108. System.out.println(id);
  109. }
  110. }
  111.  
  112. }
  113. }
Success #stdin #stdout 0.15s 54528KB
stdin
11
Sachin
100
International
One day
12
Shewag
133
International
Test
13
Varun
78
State
Test
14
Ashwin
67
State
One day
State
Test
stdout
67
13
12