洛谷题单2-P5709 【深基2.习6】Apples Prologue 苹果和虫子-python-流程图重构

题目描述

小 B 喜欢吃苹果。她现在有 mmm1≤m≤1001 \le m \le 1001m100)个苹果,吃完一个苹果需要花费 ttt0≤t≤1000 \le t \le 1000t100)分钟,吃完一个后立刻开始吃下一个。现在时间过去了 sss1≤s≤100001 \le s \le 100001s10000)分钟,请问她还有几个完整的苹果?

输入格式

输入三个非负整数表示 m,t,sm, t, sm,t,s

输出格式

输出一个整数表示答案。

输入输出样例

输入

50 10 200

输出

30

说明/提示

如果你出现了 RE,不如检查一下被零除?

方式

代码

class Solution:
    @staticmethod
    def oi_input():
        """从标准输入读取数据"""
        m, t, s = map(int, input().split())
        return m, t, s

    @staticmethod
    def oi_test():
        """提供测试数据"""
        return 50, 10, 200

    @staticmethod
    def solution(m, t, s):
        '''边界值和分母为零'''
        is_normal = True
        if t == 0 and is_normal:
            print(0)
            is_normal = False
        if m * t <= s and is_normal:
            print(0)
            is_normal = False
        if is_normal:
            result = m - s // t if s % t == 0 else m - s // t - 1
            print(result)

oi_input = Solution.oi_input
oi_test = Solution.oi_test
solution = Solution.solution

if __name__ == '__main__':
    pass
    m, t, s = oi_test()
    # m, t, s = oi_input()
    solution(m, t, s)

流程图

最终计算
条件处理模块
result = m - s//t
result = m - s//t -1
打印result
初始化 is_normal = True
调用 solution(m, t, s)
t == 0?
打印0\nis_normal=False
m×t ≤ s?
打印0\nis_normal=False
计算余数条件:s%t == 0?
开始
主函数
调用 oi_test()
获取测试数据 m=50, t=10, s=200
结束
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值