[Java] 蓝桥杯ALGO-120 算法训练 学做菜

问题描述
涛涛立志要做新好青年,他最近在学做菜。由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上字母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);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值