import java.io.* ;
public class MclaLoops//Class
{
public static void main (String[] args) throws IOException //main method
{
BufferedReader objReader = new BufferedReader (new InputStreamReader(System.in));
System.out.println("Please enter the cost for a purple ticket"); //input prompt for cost of purple ticket
int purpleTicket = Integer.parseInt ((objReader.readLine())); //varible decleration for purple ticket
System.out.println("Please enter the cost for a gray ticket"); //input prompt for cost of gray ticket
int grayTicket = Integer.parseInt ((objReader.readLine()));// varible decleration for gray ticket
System.out.println("Please enter the cost for a yellow ticket"); //inpur prompt for cost of yellow ticket
int yellowTicket =Integer.parseInt ((objReader.readLine())); //variable decleration for yellow ticket
System.out.println("Please enter the cost for a brown ticket"); // input prompt for cost of brown ticket
int brownTicket = Integer.parseInt ((objReader.readLine())); // variable decleration for brown ticket
System.out.println("PLease enter the amount of money you would want to rasie"); // input for raisedMoney money to be raised in ticket sales
int raisedMoney = Integer.parseInt ((objReader.readLine ())); // variable decleration for the money that is to be raised
int ctr1 = 0; //counter one, counting how many brown tickets there will be
int ctr2 = 0; // counter two, counting how many yellow tickets there will be
int ctr3 = 0; // counter three, counting how many gray tickets there will be
int ctr4 = 0; //counter four, counting how many purple tickets there will be
int ctrCombo = 0; // counter to keep track of raisedMoney combinations
int brownMax = 0; // variable for max amount of brown tickets for a given raised amount
int yellowMax = 0; // variable for max amount of yellow tickets for a given raised amount
int grayMax = 0; // variable for max amount of gray tickets for a given raised amount
int purpleMax = 0;// variable for max amount of purple tickets for a given raised amount
int r = raisedMoney = 0; // declaring raised amount to r
int ctr = 0;
int min = 999999;
if (brownTicket <= r) // if the brown ticket cost is less than or equal to the raisedMoney raised amount then execute
{
r = raisedMoney;
brownMax = (r / brownTicket); // finding the maximum times the brown ticket can go into the raisedMoney raised amount
}
if (yellowTicket <= r)//if the yellow ticket cost is less than or equal to the raisedMoney raised amount then execute
{
r = raisedMoney;
yellowMax = (r / yellowTicket);// finding the maximum times the yellow ticket can go into the raisedMoney raised amount
}
if (grayTicket <= r) //if the gray ticket cost is less than or equal to the raisedMoney raised amount then execute
{
r = raisedMoney;
grayMax = (r / grayTicket);// finding the maximum times the gray ticket can go into the raisedMoney raised amount
}
if (purpleTicket <= r) //if the purple ticket cost is less than or equal to the raisedMoney raised amount then execute
{
r = raisedMoney;
purpleMax = (r / purpleTicket);// finding the maximum times the purple ticket can go into the raisedMoney raised amount
}
if((brownTicket > 0) || (yellowTicket >0) || (grayTicket >0) || (purpleTicket >0)) //Error checking
{
r = raisedMoney;
do
{
r = raisedMoney; // setting raised money to be assigned to r
// resetting each ctr to 0 once the loop starts again
ctr1 = 0;
ctr2 = 0;
ctr3 = 0;
ctr4 = 0;
r= r - (brownTicket * brownMax); // subtracting the max brown tickets from the raisedMoney raised amount needed
ctr1 = ctr1 * brownMax; // adding a counter to brown
while (yellowTicket <= r) //keep adding 1 to the counter while the yellowTicket is less than or equal too the raised amount
{
ctr2++;
r = r - yellowTicket; // subtract the yellow ticket from the raised price if possible
}
while (grayTicket <= r)
{
ctr3++;
r = r - grayTicket;
}
while (purpleTicket <= r)
{
ctr4++;
r = r - purpleTicket;
}
if (ctr1 + ctr2 + ctr3 + ctr4 < min)
{
min = ctr1 + ctr2 + ctr3 + ctr4;
}
if (r == raisedMoney)
{
ctrCombo = ctrCombo + 1;
{
ctr++;
System.out.println ("# of PURPLE is " + ctr4 + " # of GRAY is " + ctr3 + " # of YELLOW is " + ctr2 + " # of PURPLE is " + ctr1);
yellowMax = yellowMax -1;
}
}
} while (yellowMax > 0);
r = raisedMoney;
do
{
r = raisedMoney;
ctr1 = 0;
ctr2 = 0;
ctr3 = 0;
ctr4 = 0;
r= r - (yellowTicket * yellowMax);
ctr2 = ctr2 * yellowMax;
while (grayTicket <= r)
{
ctr3++;
r = r - grayTicket;
}
while (purpleTicket <= r)
{
ctr4++;
r = r - purpleTicket;
}
if (ctr1 + ctr2 + ctr3 + ctr4 < min)
{
min = ctr1 + ctr2 + ctr3 + ctr4;
}
if (r == raisedMoney)
{
ctrCombo = ctrCombo + 1;
{
ctr++;
System.out.println ("# of PURPLE is " + ctr4 + " # of GRAY is " + ctr3 + " # of YELLOW is " + ctr2 + " # of PURPLE is " + ctr1);
grayMax = grayMax -1;
}
}
} while (yellowMax > 0);
r = raisedMoney;
do
{
r = raisedMoney;
ctr1 = 0;
ctr2 = 0;
ctr3 = 0;
ctr4 = 0;
r= r - (grayTicket * grayMax);
ctr3 = ctr3 * grayMax;
while (purpleTicket <= r)
{
ctr4++;
r = r - purpleTicket;
}
if (ctr1 + ctr2 + ctr3 + ctr4 < min)
{
min = ctr1 + ctr2 + ctr3 + ctr4;
}
if (r == raisedMoney)
{
ctrCombo = ctrCombo + 1;
{
ctr++;
System.out.println ("# of PURPLE is " + ctr4 + " # of GRAY is " + ctr3 + " # of YELLOW is " + ctr2 + " # of PURPLE is " + ctr1);
purpleMax = purpleMax -1;
}
}
} while (grayMax > 0);
r = raisedMoney;
do
{
r = raisedMoney;
ctr1 = 0;
ctr2 = 0;
ctr3 = 0;
ctr4 = 0;
r= r - (purpleTicket * purpleMax);
ctr2 = ctr2 * purpleMax;
if (ctr1 + ctr2 + ctr3 + ctr4 < min)
{
min = ctr1 + ctr2 + ctr3 + ctr4;
}
if (r == raisedMoney)
{
ctrCombo = ctrCombo + 1;
{
ctr++;
System.out.println ("# of PURPLE is " + ctr4 + " # of GRAY is " + ctr3 + " # of YELLOW is " + ctr2 + " # of PURPLE is " + ctr1);
brownMax = brownMax -1;
}
}
} while (purpleMax == raisedMoney);
}
else
{
System.out.println("Invalid value(s)");
}
System.out.println ("there are " + ctrCombo + " combinations");
}
}