fork download
  1. /* package whatever; // don't place package name! */
  2. import java.util.*;
  3. import java.util.Scanner;
  4. import java.util.Arrays;
  5. class Ideone{
  6. public static void main(String[] args){
  7. Scanner sc=new Scanner(System.in);
  8. Player[] ar=new Player[4];
  9. for(int i=0;i<4;i++){
  10. int a=sc.nextInt();
  11. sc.nextLine();
  12. String b=sc.nextLine();
  13. int c=sc.nextInt();
  14. sc.nextLine();
  15. String d=sc.nextLine();
  16. String e=sc.nextLine();
  17. ar[i]=new Player(a,b,c,d,e);
  18. }
  19. String new_player=sc.nextLine();
  20. String new_match=sc.nextLine();
  21. int out=runs(ar,new_player);
  22. if(out!=0)
  23. System.out.println(out);
  24. else
  25. System.out.println("No such player");
  26. int[] obj=find(ar,new_match);
  27. if(obj!=null){
  28. for(int i=0;i<obj.length;i++){
  29. System.out.println(obj[i]);
  30. }
  31. }
  32. else
  33. System.out.println("No Player with given match Type");
  34. }
  35. public static int runs(Player[] ar1,String new_player){
  36. int[] help=new int[0];
  37. for(int i=0;i<4;i++){
  38. if(ar1[i].player_type.equalsIgnoreCase(new_player)){
  39. help=Arrays.copyOf(help,help.length+1);
  40. help[help.length-1]=ar1[i].runs;
  41.  
  42. }
  43. }
  44. if(help.length>0){
  45. for(int i=0;i<help.length-1;i++){
  46. for(int j=0;j<help.length-1;j++){
  47. if(help[j]>help[j+1]){
  48. int temp=help[j+1];
  49. help[j+1]=help[j];
  50. help[j]=temp;
  51. }
  52. }
  53. }
  54. return help[0];
  55. }
  56. return 0;
  57. }
  58. public static int[] find(Player[] ar1,String new_match){
  59. int[] help=new int[0];
  60. for(int i=0;i<4;i++){
  61. if(ar1[i].match_type.equalsIgnoreCase(new_match)){
  62. help=Arrays.copyOf(help,help.length+1);
  63. help[help.length-1]=ar1[i].id;
  64. }
  65. }
  66. if(help.length>0){
  67. for(int i=0;i<help.length-1;i++){
  68. for(int j=0;j<help.length-1;j++){
  69. if(help[j]<help[j+1]){
  70. int temp=help[j+1];
  71. help[j+1]=help[j];
  72. help[j]=temp;
  73. }
  74. }
  75. }
  76. return help;
  77. }
  78. return null;
  79. }
  80. }
  81. class Player{
  82. int id;
  83. String name;
  84. int runs;
  85. String player_type;
  86. String match_type;
  87. public Player(int id,String name,int runs,String player_type,String match_type){
  88. this.id=id;
  89. this.name=name;
  90. this.runs=runs;
  91. this.player_type=player_type;
  92. this.match_type=match_type;
  93. }
  94. }
Success #stdin #stdout 0.14s 51356KB
stdin
11
Sachin
100
International
One day
12
Sehwag
133
International
Test
13
Varun
78
State
Test
14
Ashwin
67
State
One day
Ranji
T20
stdout
No such player
No Player with given match Type