• 算法训练 学做菜


    /*
    算法训练 学做菜  
    
    问题描述
      涛涛立志要做新好青年,他最近在学做菜。由于技术还很生疏,他只会用鸡蛋,西红柿,鸡丁,辣酱这四种原料来做菜,我们给这四种原料标上字母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
    
    */
    import java.util.Scanner;
    
    public class Main {
        public static void main(String args[]) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int aa = 0;
            int bb = 0;
            int cc = 0;
            int dd = 0;
            int ee = 0;
            while (a - 2 >= 0 && b - 1 >= 0 && d - 2 >= 0) {
                aa++;
                a = a - 2;
                b = b - 1;
                d = d - 2;
            }
            while (a - 1 >= 0 && b - 1 >= 0 && c - 1 >= 0 && d - 1 >= 0) {
                bb++;
                a = a - 1;
                b = b - 1;
                c = c - 1;
                d = d - 1;
            }
            while (c - 2 >= 0 && d - 1 >= 0) {
                cc++;
                c = c - 2;
                d--;
            }
            while (b - 3 >= 0) {
                dd++;
                b = b - 3;
            }
            while (a - 1 >= 0 && d - 1 >= 0) {
                ee++;
                a--;
                d--;
            }
            System.out.println(aa);
            System.out.println(bb);
            System.out.println(cc);
            System.out.println(dd);
            System.out.println(ee);
        }
    
    }
  • 相关阅读:
    从标准输入读取一行字符串的方法
    输入文件包含若干行,不知何时结束时,如何读入数据
    centos7.5 + docker + mysql5.7 多实例安装
    copula函数及其Var计算的Python实现
    让网络机器人看起来像人类用户
    流畅的python读书笔记
    神经网络层数和神经元数目 的一些建议
    SVM算法Python实现
    预测性维护{维修}又称:预知性、预见性维护{维修})
    WebDriver API 元素定位(Python)
  • 原文地址:https://www.cnblogs.com/Alpharun/p/8623785.html
Copyright © 2020-2023  润新知