Programming - soy sauce

 

  1. Soy sauce

 Problem Description

  Xiao Ming with N dollars to buy soy sauce. Soy sauce bottle 10 dollars, the merchant promotions, every buy 3 bottles get a bottle, or bought each 5 bottles get 2 bottles. I ask how much a bottle of soy sauce Xiao Ming can get up to.

Input Format

  The first line of the input contains an integer N , Bob can be used to represent the amount of money to buy soy sauce. N is an integer multiple of 10, N is not more than 300.

Output Format

  Output An integer that indicates how much a bottle of soy sauce Xiao Ming can get up to.

Sample input

40

Sample Output

5

Sample Description

  Into the 40 yuan 30 and $ 10 yuan, buy bottles and bottle 3, respectively, wherein a feeding bottle 3 bottles, 5 bottles were obtained.

Sample input

80

Sample Output

11

Sample Description

Into the 80 yuan 30 and $ 50, and 5 to buy three bottles each bottle, wherein the bottle 3 1 bottle feeding, feeding bottles 5 bottles 2, to give a total of 11 bottles.

 

public class Main {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int count = 0;
  
  if(n>=50)
  {
   int k = n/50;
   count+=(k*7);
   n = n-(k*50);
   if(n>=30)
   {
    int k1 = n/30;
    count+=(k1*4);
    n = n-(k1*30);
    if(n>=10)
    {
     int k2 = n/10;
     count+=k2;
    }
   }else{
    int k3 = n/10;
    count+=k3;
   }
    
  }else{
   if(n>=30)
   {
    int k1 = n/30;
    count+=(k1*4);
    n = n-(k1*30);
    if(n>=10)
    {
     int k2 = n/10;
     count+=k2;
    }
   }else{
    int k3 = n/10;
    count+=k3;
   }
  }
  
  System.out.println(count);
 }
}

 

​ 

Guess you like

Origin blog.csdn.net/weixin_41808843/article/details/88979736