a
This commit is contained in:
1 parent
4b00d5838c
commit
a31c9233d0
3 files changed
+96
-4
No files matched your search
+4
-1
@@ -10,6 +10,9 @@ public class Test {
|
||||
boolean continueBuy = true;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
while (continueBuy) {
|
||||
System.out.println("Ticket Seller: Five Yuan - " + ts.getFive() + ", Ten Yuan - " + ts.getTen()
|
||||
+ ", Twenty Yuan - " + ts.getTwenty() + ", Fifty Yuan - " + ts.getFifty() + ", Hundred Yuan - "
|
||||
+ ts.getHundred());
|
||||
System.out.print("Please enter your name: ");
|
||||
name = sc.nextLine();
|
||||
System.out.print("Please enter your payment: ");
|
||||
@@ -17,7 +20,7 @@ public class Test {
|
||||
Thread consumer = new Thread(ts, name + "-" + payment);
|
||||
consumer.start();
|
||||
try {
|
||||
consumer.join();
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -44,15 +44,52 @@ public class TicketSeller implements Runnable {
|
||||
}
|
||||
break;
|
||||
case 50:
|
||||
if (ten > 0 && five > 0) {
|
||||
ten--;
|
||||
if (twenty > 1 && five > 0) {
|
||||
twenty -= 2;
|
||||
five--;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (five >= 3) {
|
||||
} else if (ten > 1 && twenty > 0 && five > 0) {
|
||||
ten -= 2;
|
||||
twenty--;
|
||||
five--;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (ten > 3 && five > 0) {
|
||||
ten -= 4;
|
||||
five--;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (twenty > 0 && ten > 0 && five > 2) {
|
||||
twenty--;
|
||||
ten--;
|
||||
five -= 3;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (ten > 2 && five > 2) {
|
||||
ten -= 3;
|
||||
five -= 3;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (twenty > 0 && five > 4) {
|
||||
twenty--;
|
||||
five -= 4;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (ten > 1 && five > 4) {
|
||||
ten -= 2;
|
||||
five -= 4;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (ten > 0 && five > 6) {
|
||||
ten--;
|
||||
five -= 6;
|
||||
fifty++;
|
||||
success = true;
|
||||
} else if (five > 9) {
|
||||
five -= 10;
|
||||
fifty++;
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -71,4 +108,44 @@ public class TicketSeller implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getFive() {
|
||||
return five;
|
||||
}
|
||||
|
||||
public void setFive(int five) {
|
||||
this.five = five;
|
||||
}
|
||||
|
||||
public int getTen() {
|
||||
return ten;
|
||||
}
|
||||
|
||||
public void setTen(int ten) {
|
||||
this.ten = ten;
|
||||
}
|
||||
|
||||
public int getTwenty() {
|
||||
return twenty;
|
||||
}
|
||||
|
||||
public void setTwenty(int twenty) {
|
||||
this.twenty = twenty;
|
||||
}
|
||||
|
||||
public int getFifty() {
|
||||
return fifty;
|
||||
}
|
||||
|
||||
public void setFifty(int fifty) {
|
||||
this.fifty = fifty;
|
||||
}
|
||||
|
||||
public int getHundred() {
|
||||
return hundred;
|
||||
}
|
||||
|
||||
public void setHundred(int hundred) {
|
||||
this.hundred = hundred;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
def find_combinations():
|
||||
combinations = []
|
||||
for i in range(10):
|
||||
for j in range(5):
|
||||
for k in range(3):
|
||||
if 5 * i + 10 * j + 20 * k == 45:
|
||||
combinations.append((i, j, k))
|
||||
return combinations
|
||||
|
||||
|
||||
combinations = find_combinations()
|
||||
print(f"The combinations of 5, 10, and 20 that sum up to 45 are: {combinations}")
|
||||
Reference in new issue
Block a user