1.4 21: Apples and bugs 2

Description
You bought a box of n apples, and unfortunately a bug was mixed in the box when you finished buying. A worm can eat an apple every x hours. If the worm does not eat one apple before another, how many whole apples do you have after y hours?

Input
Input only one line, including n, x and y (all integers).
Output The
output is only one line, the number of apples left.
Sample input
10 4 9
Sample output
7

#include <iostream>
#include <cmath> 
using namespace std;
int main()
{
    
    
	int n,x,y;
	cin >>n>>x>>y;
	if(y%x==0)
	{
    
    
		cout<<n-y/x<<endl;
	} else if(n-y/x < 0)
	{
    
    
		cout<<0<<endl;
	}else
	{
    
    
		cout<<n-y/x-1<<endl;
	}
	
	return 0;
}

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/111614445