网易2018校招在线编程题-第一题

package com.neitui.demo1;

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();//每个水果p元
		int count = 0;
		//先解决异常情况
		if(b > c/a){
			count = c/a;
		}else{
			count = b;
		}
		c = c - count*a;
		b = b -	count;
		while(c>0){
			c=c-a-d;
			if(c<0){
				break;
			}
			count++;
		}
		System.out.println(count);
	}
}

你可能感兴趣的:(algorithm,Practice,Java算法之路)