Skip to content

Instantly share code, notes, and snippets.

@henvic
Created July 11, 2014 22:32
Show Gist options
  • Save henvic/28977cd5e65189d9ede6 to your computer and use it in GitHub Desktop.
Save henvic/28977cd5e65189d9ede6 to your computer and use it in GitHub Desktop.
public class T2Q1 {
Arquivo io;
int[] coins = new int[] {1, 5, 10, 25, 50};
public void printChange(int change, int[] amounts) {
int amountCoins = 0;
int length = amounts.length;
int pos = length - 1;
int left = change;
int[] used = new int[5];
while(left != 0 && pos >= 0) {
if (left < coins[pos] || used[pos] == amounts[pos]) {
pos -= 1;
continue;
}
left -= coins[pos];
used[pos] += 1;
}
for (int c : used) {
amountCoins += c;
}
if (left != 0) {
amountCoins += 10000;
}
System.out.println(change + ":" + amountCoins);
}
public void evaluate() {
int max = io.readInt();
int[] amounts = new int[] {
io.readInt(),
io.readInt(),
io.readInt(),
io.readInt(),
io.readInt()
};
for (int change = 1; change <= max; change += 1) {
printChange(change, amounts);
}
System.out.println("");
}
public void run() {
int cases;
io = new Arquivo("T2Q1.in", "T2Q1.out");
cases = io.readInt();
while (cases > 0) {
evaluate();
cases -= 1;
}
}
public static void main(String[] args) {
new T2Q1().run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment