import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int objectSize = sc.nextInt();
player []arr = new player[objectSize];
for(int i =0;i<objectSize;i++)
{
int pId = sc.nextInt();sc.nextLine();
String pName = sc.nextLine();
int run = sc.nextInt();sc.nextLine();
String pType = sc.nextLine();
String PmatchType = sc.nextLine();
arr[i] =new player(pId, pName, run, pType, PmatchType);
}
String pType = sc.nextLine();
String PmatchType = sc.nextLine();
int output1 = findPlayerWithLowestRuns(arr, pType);
player [] output2 = findPlayerByMatchType(arr, PmatchType);
if(output1>0)
System.out.println(output1);
else
System.out.println("No Such player");
if(output2!=null)
{
for(int i = 0;i<output2.length;i++)
{
System.out.println(output2[i].getplayerId());
}
}
else
{
System.out.println("No player given match type");
}
}
public static int findPlayerWithLowestRuns(player []arr, String playerType)
{
int lruns = 0;
boolean cond = false;
for(int i =0;i<arr.length;i++)
{
if(playerType.equals(arr[i].getplayerType()))
{
cond = true;
lruns = arr[i].getruns();
if(arr[i].getruns()<lruns)
lruns = arr[i].getruns();
}
}
if(cond==true)
return lruns;
else
return 0;
}
public static player[] findPlayerByMatchType(player[] arr, String matchType)
{
int count = 0;
player temp;
int out = 0;
boolean mcond = false;
for(int i = 0;i<arr.length;i++)
{
if(matchType.equals(arr[i].getmatchType()))
{
mcond = true;
count++;
}
}
player [] arr1 = new player[count];
for(int i = 0;i<arr.length;i++)
{
if(matchType.equals(arr[i].getmatchType()))
{
arr1[out++] = arr[i];
}
}
for(int i =0;i<count;i++)
{
for(int j=i+1;j<count;j++)
{
if(arr1[i].getplayerId()<arr1[j].getplayerId())
{
temp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = temp;
}
}
}
if(mcond==true)
{
return arr1;
}
else
return null;
}
}
class player
{
private int playerId;
private String playerName;
private int runs;
private String playerType;
private String matchType;
player(int playerId, String playerName, int runs, String playerType, String matchType)
{
this.playerId = playerId;
this.playerName = playerName;
this.runs = runs;
this.playerType = playerType;
this.matchType = matchType;
}
public int getplayerId()
{
return playerId;
}
public void setplayerId(int playerId)
{
this.playerId = playerId;
}
public String getplayerName()
{
return playerName;
}
public void setplayerName(String playerName)
{
this.playerName = playerName;
}
public int getruns()
{
return runs;
}
public void setruns(int runs)
{
this.runs = runs;
}
public String getplayerType()
{
return playerType;
}
public void setplayerType(String playerType)
{
this.playerType = playerType;
}
public String getmatchType()
{
return matchType;
}
public void setmatchType(String matchType)
{
this.matchType = matchType;
}
}
Comments
Post a Comment