-
Notifications
You must be signed in to change notification settings - Fork 0
/
LemonadeCharge.c
41 lines (39 loc) · 990 Bytes
/
LemonadeCharge.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdbool.h>
#include <stdio.h>
bool lemonadeChange(int* bills, int billsSize) {
int cash_5=0, cash_10=0;
for(int i=0; i<billsSize; i++){
if(bills[i]==5){
cash_5++;
}else if(bills[i]==10){
if(cash_5>0){
cash_10++;
cash_5--;
}else{
return false;
}
}else if(bills[i]==20){
if(cash_10>0 && cash_5>0){
cash_10--;
cash_5--;
}else if(cash_5>2){
cash_5=cash_5-3;
}else{
return false;
}
}
}
return true;
}
int main() {
// Exemplo de uso da função
int bills[] = {5, 10, 20, 5, 5};
int size = sizeof(bills) / sizeof(bills[0]);
bool result = lemonadeChange(bills, size);
if (result) {
printf("e possivel dar o troco .\n");
} else {
printf("Nao e possivel dar o troco.\n");
}
return 0;
}