谢谢!!!!!!!!!!!!!!!
2026-02-20 20:20:08
发布于:四川
7阅读
0回复
0点赞
为什么if(y%x!=0){
cout<<n-y/x-1;
}
if(n-y/x<=0){
cout<<"0";
}
全部评论 2
存在的问题:
当n-y/x<=0且y%x!=0时,两个条件都会执行,会输出两个结果
没有处理y%x==0且n-y/x>0的情况
更合理的写法应该是:
int result = n - y/x;
if(y%x != 0) {
result--;
}
if(result <= 0) {
cout << "0";
} else {
cout << result;
}
或者用更简洁的方式:
int result = n - (y + x - 1) / x; // 向上取整除法
if(result <= 0) {
cout << "0";
} else {
cout << result;
}昨天 来自 江西
1111
昨天 来自 河北
0














有帮助,赞一个