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

题目描述

小 B 喜欢吃苹果。她现在有 m m m( 1 ≤ m ≤ 100 1 \le m \le 100 1≤m≤100)个苹果,吃完一个苹果需要花费 t t t( 0 ≤ t ≤ 100 0 \le t \le 100 0≤t≤100)分钟,吃完一个后立刻开始吃下一个。现在时间过去了 s s s( 1 ≤ s ≤ 10000 1 \le s \le 10000 1≤s≤10000)分钟,请问她还有几个完整的苹果?

输入格式

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

输出格式

输出一个整数表示答案。

输入输出样例

输入

复制代码
50 10 200

输出

复制代码
30

说明/提示

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

方式

代码

python 复制代码
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 结束

相关推荐
未来之窗软件服务1 分钟前
计算机二级[英文]-C 字符串移动—东方仙盟
c语言·开发语言·仙盟创梦ide·东方仙盟
Wang's Blog3 分钟前
Java框架快速入门: Spring Security+OAuth2之过滤器与过滤器链
java·开发语言·spring
谢尔登24 分钟前
01_Java基础速通
java·开发语言
前端炒粉24 分钟前
DOM 常用 API 速查表
开发语言·javascript·ecmascript
枫彩44 分钟前
A股数据源怎么选?用 Python 验收 AI 复盘的日期与明细
python·ai agent·股票数据·mcp
2601_962382431 小时前
Python 代码不可不知的函数式编程技术
python·函数式编程·高阶函数·嵌套函数·头等函数
2601_962078031 小时前
Python办公自动化与数据分析实战 培训班2021年
python·数据分析·办公自动化·自动化办公·实战演练
带多刺的玫瑰1 小时前
Leecode#26刷题之删除有序数组中的重复项
数据结构·算法·leetcode
用户938515635071 小时前
Text2SQL 实战:用 DeepSeek 大模型实现自然语言查询 SQLite 数据库
python·sqlite
2601_962099682 小时前
Python环境下中文分词实现与应用探索
python·自然语言处理·中文分词·jieba·开源社区