2018秋-阿里巴巴-编程题1

2018秋-阿里巴巴-编程题1

阿里巴巴的食堂搞活动促销,已知某饮料1瓶3元钱,4个瓶盖可以换一瓶,2个空瓶可以换一瓶,则30元最多可以喝几瓶。
输入:
A //A表示饮料单价
B //B表示瓶盖换瓶比
C //C表示空瓶换瓶比
D //D表示给定的钱数
输出:S
例:
输入:
3
4
2
30
输出:
35

package Test;

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int price=sc.nextInt();
        int tapNewRate=sc.nextInt();
        int bottomNewRate=sc.nextInt();
        int money=sc.nextInt();
        int tapNum=0;
        int bottomNum=0;
        int total=0;
        while(money>=price||tapNum>=tapNewRate||bottomNum>=bottomNewRate){
            if(money>=price){
                money-=price;
                total++;
                tapNum++;
                bottomNum++;
            }
            if(tapNum>=tapNewRate){
                tapNum-=tapNewRate;
                total++;
                tapNum++;
                bottomNum++;
            }
            if(bottomNum>=bottomNewRate){
                bottomNum-=bottomNewRate;
                bottomNum++;
                total++;
                tapNum++;
            }
        }
        System.out.println(total);
    }
}
posted @ 2020-03-19 23:42  别再闹了  阅读(45)  评论(0)    收藏  举报