全部评论 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;
    }

    昨天 来自 江西

    1
  • 111

    昨天 来自 河北

    0

热门讨论