Problem P08. [算法课蛮力法] 柠檬水找零
多个判断,简单题
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int bills[3]={0};
int main()
{
bool flag=true;
while(1){
int ret;
int bill;
ret = scanf("%d", &bill);
if (ret==EOF){
break;
}
if (bill==5){
bills[1]++;
}else if (bill==10&&bills[1]>0){
bills[1]--;
bills[2]++;
}else if (bill==20&&bills[1]>0){
if (bills[2]>0){
bills[2]--;
bills[1]--;
}else if (bills[1]>2){
bills[1]-=3;
}else {
flag = false;
break;
}
}else {
flag = false;
break;
}
}
if (flag==true){
printf("true");
}else {
printf("false");
}
return 0;
}