import java.io.* ; public class AmirLoops { public static void main (String[] args) throws IOException { BufferedReader objReader = new BufferedReader (new InputStreamReader (System.in)); // Variable Declaration double ctrPurp = 0; double ctrGray = 0; double ctrYell = 0; double ctrBrow = 0; double comboYell = 0; double comboBrow = 0; double comboGray = 0; double comboPurp = 0; double ctrFinal = 0; double minimum = 999999; // Inputs System.out.println ("How much does a purple ticket cost?"); double purp = Double.parseDouble ((objReader.readLine())); System.out.println ("How much does a gray ticket cost?"); double gray = Double.parseDouble ((objReader.readLine())); System.out.println ("How much does a yellow ticket cost?"); double yell = Double.parseDouble ((objReader.readLine())); System.out.println ("How much does a brown ticket cost?"); double brow = Double.parseDouble ((objReader.readLine())); System.out.println ("How much must be raised with ticket sales?"); double total = Double.parseDouble ((objReader.readLine())); // Processing if ((purp <= total) || (gray <= total) || (yell <= total) || (brow <= total)) // Error Checking { System.out.println ("Combinations are:"); // Starting Output, placed here because it will not loop like other outputs System.out.println (" "); // Space if (purp <= total) // Finding maximum number of purple tickets to be sold { comboPurp = total/purp; } if (gray <= total) // Finding maximum number of gray tickets to be sold { comboGray = total/gray; } if (yell <= total) // Finding maximum number of yellow tickets to be sold { comboYell = total/yell; } if (brow <= total) // Finding maximum number of brown tickets to be sold { comboBrow = total/brow; } if (brow <= total) { do // Brown Ticket loop, to continuously check it { ctrPurp = 0; // Reseting counters ctrGray = 0; ctrYell = 0; ctrBrow = 0; total = total - (comboBrow * brow); // Total subtract the number of brown tickets ctrBrow= ctrBrow + comboBrow; while (purp <= total) // Remaining ticket numbers { total = total - purp; ctrPurp++; } while (gray <= total) // Remaining ticket numbers { total = total - gray; ctrGray++; } while (yell <= total) // Remaining ticket numbers { total = total - yell; ctrYell++; } if ((ctrBrow + ctrPurp + ctrGray + ctrYell) < minimum) // Finding lowest possible combinations { minimum = ctrBrow + ctrPurp + ctrGray + ctrYell; } if (((ctrBrow * brow) + (ctrPurp * purp) + (ctrGray * gray) + (ctrYell * yell)) % total == 0) // Finding total number of combinations { ctrFinal++; System.out.println ("# of PURPLE is " + ctrPurp + " # of GRAY is " + ctrGray + " # of YELLOW is " + ctrYell + " # of BROWN is " + ctrBrow); // Output comboBrow--; } } while (comboBrow > 0); } if (yell <= total) { do // Yellow Ticket loop, to continuously check it { ctrPurp = 0; // Reseting counters ctrGray = 0; ctrYell = 0; ctrBrow = 0; total = total - (comboYell * yell); // Total subtract the number of yellow tickets ctrYell= ctrYell + comboYell; while (purp <= total) // Remaining ticket numbers { total = total - purp; ctrPurp++; } while (gray <= total) // Remaining ticket numbers { total = total - gray; ctrGray++; } while (brow <= total) // Remaining ticket numbers { total = total - brow; ctrBrow++; } if ((ctrBrow + ctrPurp + ctrGray + ctrYell) < minimum) // Finding lowest possible combinations { minimum = ctrBrow + ctrPurp + ctrGray + ctrYell; } if (((ctrBrow * brow) + (ctrPurp * purp) + (ctrGray * gray) + (ctrYell * yell)) % total == 0) // Finding total number of combinations { ctrFinal++; System.out.println ("# of PURPLE is " + ctrPurp + " # of GRAY is " + ctrGray + " # of YELLOW is " + ctrYell + " # of BROWN is " + ctrBrow); // Output comboYell--; } } while (comboYell > 0); } if (gray <= total) { do // Gray Ticket loop, to continuously check it { ctrPurp = 0; // Reseting counters ctrGray = 0; ctrYell = 0; ctrBrow = 0; total = total - (comboGray * gray); // Total subtract the number of yellow tickets ctrGray= ctrGray + comboGray; while (purp <= total) // Remaining ticket numbers { total = total - purp; ctrPurp++; } while (yell <= total) // Remaining ticket numbers { total = total - yell; ctrYell++; } while (brow <= total) // Remaining ticket numbers { total = total - brow; ctrBrow++; } if ((ctrBrow + ctrPurp + ctrGray + ctrYell) < minimum) // Finding lowest possible combinations { minimum = ctrBrow + ctrPurp + ctrGray + ctrYell; } if (((ctrBrow * brow) + (ctrPurp * purp) + (ctrGray * gray) + (ctrYell * yell)) % total == 0) // Finding total number of combinations { ctrFinal++; System.out.println ("# of PURPLE is " + ctrPurp + " # of GRAY is " + ctrGray + " # of YELLOW is " + ctrYell + " # of BROWN is " + ctrBrow); // Output comboGray--; } } while (comboGray > 0); } if (purp <= total) { do // Purple Ticket loop, to continuously check it { ctrPurp = 0; // Reseting counters ctrGray = 0; ctrYell = 0; ctrBrow = 0; total = total - (comboPurp * purp); // Total subtract the number of yellow tickets ctrPurp= ctrPurp + comboPurp; while (gray <= total) // Remaining ticket numbers { total = total - gray; ctrGray++; } while (yell <= total) // Remaining ticket numbers { total = total - yell; ctrYell++; } while (brow <= total) // Remaining ticket numbers { total = total - brow; ctrBrow++; } if ((ctrBrow + ctrPurp + ctrGray + ctrYell) < minimum) // Finding lowest possible combinations { minimum = ctrBrow + ctrPurp + ctrGray + ctrYell; } if (((ctrBrow * brow) + (ctrPurp * purp) + (ctrGray * gray) + (ctrYell * yell)) % total == 0) // Finding total number of combinations { ctrFinal++; System.out.println ("# of PURPLE is " + ctrPurp + " # of GRAY is " + ctrGray + " # of YELLOW is " + ctrYell + " # of BROWN is " + ctrBrow); // Output comboPurp--; } } while (comboPurp > 0); } System.out.println (" "); System.out.println ("Total combinations is " + ctrFinal); System.out.println (" "); System.out.println ("Minimum number of tickets to print is " + minimum); } } }