CSP 2017.9 第一題 打醬油 java代碼

來源:互聯網
上載者:User

問題描述
  小明帶著N元錢去買醬油。醬油10塊錢一瓶,商家進行促銷,每買3瓶送1瓶,或者每買5瓶送2瓶。請問小明最多可以得到多少瓶醬油。
輸入格式
  輸入的第一行包含一個整數N,表示小明可用於買醬油的錢數。N是10的整數倍,N不超過300。
輸出格式
  輸出一個整數,表示小明最多可以得到多少瓶醬油。
範例輸入 40

範例輸出 5

範例說明
  把40元分成30元和10元,分別買3瓶和1瓶,其中3瓶送1瓶,共得到5瓶。
範例輸入 80

範例輸出 11

範例說明
  把80元分成30元和50元,分別買3瓶和5瓶,其中3瓶送1瓶,5瓶送2瓶,共得到11瓶。

package com.CavellChance.learning;import java.util.Scanner;public class BuySomeSauce {    public static int bigSale(int m){        int bottle5 =  m / 50;        int bottle5Left = m % 50;        int bottle3 = bottle5Left / 30;        int bottle3Left = bottle5Left % 30;        int bottle1 = bottle3Left / 10;        int bottles = bottle5 * 7 + bottle3 * 4 + bottle1 * 1;        return bottles;    }     public static void main(String args[]){        int money = 0;        Scanner scanner = new Scanner(System.in);        if(scanner.hasNextInt()){            money = scanner.nextInt();        }        System.out.println(bigSale(money));    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.