不正经题解
2026-01-26 18:32:30
发布于:上海
3阅读
0回复
0点赞
水题
要注意特判虫子把所有苹果都吃完,使现有苹果数量变为负数
#include<bits/stdc++.h>
using namespace std;
//开头
int main(){
int n,x,y;//定义n,x,y
cin>>n>>x>>y;//输入n,x,y
int ans=n;//定义一个变量用于存放现有苹果数
if(y%x==0){//虫子能正好吃完整数个苹果的情况
ans-=y/x;
}
else{//虫子不能正好吃完整数个苹果的情况
ans-=y/x+1;
}
if(ans<=0) cout<<0<<endl;//特判:虫子把所有苹果都吃完,导致ans变为负数
else cout<<ans<<endl;//否则正常输出
return 0;
}
这里空空如也




有帮助,赞一个