问题描述
涛涛立志要做新好青年,他最近在学做菜。由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上字母A,B,C,D。
涛涛现在会做的菜有五种:
1、 西红柿炒鸡蛋 原料:AABDD
2、 酸辣鸡丁 原料:ABCD
3、 宫保鸡丁 原料:CCD
4、 水煮西红柿 原料:BBB
5、 怪味蛋 原料:AD
这天早上,开开去早市给涛涛买了一些原料回来。由于事先没有什么计划,涛涛决定,对于现存的原料,每次尽量做菜单上靠前(即编号小)的菜。
现在请你写一个程序,判断一下开开和涛涛中午能吃到哪些菜。
输入格式
共4个整数a,b,c,d。分别表示开开买的A,B,C,D这4种原料的数量。每种原料不会超过30份。
输出格式
输出5行。其中第i行表示涛涛做的第i种菜的数目。
样例输入
3
1
2
4
样例输出
1
0
1
0
1
package algo120;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] foods = new int[4];
for (int i = 0; i < foods.length; i++) {
foods[i] = in.nextInt();
}
in.close();
// 1
int cnt = 0;
while (foods[0] >= 2 && foods[1] >= 1 && foods[3] >= 2) {
foods[0] -= 2;
foods[1] -= 1;
foods[3] -= 2;
cnt++;
}
System.out.println(cnt);
// 2
cnt = 0;
while (foods[0] >= 1 && foods[1] >= 1 && foods[2] >= 1 && foods[3] >= 1) {
for (int j = 0; j < foods.length; j++) {
foods[j] -= 1;
}
cnt++;
}
System.out.println(cnt);
// 3
cnt = 0;
while (foods[2] >= 2 && foods[3] >= 1) {
foods[2] -= 2;
foods[3] -= 1;
cnt++;
}
System.out.println(cnt);
// 4
cnt = 0;
while (foods[1] >= 3) {
foods[1] -= 3;
cnt++;
}
System.out.println(cnt);
// 5
cnt = 0;
while (foods[0] >= 1 && foods[3] >= 1) {
foods[0] -= 1;
foods[3] -= 1;
cnt++;
}
System.out.println(cnt);
}
}