洛谷题单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 结束

相关推荐
Shinom1ya_1 天前
算法 day 46
数据结构·算法
你才是向阳花1 天前
如何用Python实现飞机大战小游戏
开发语言·python·pygame
合作小小程序员小小店1 天前
web网页开发,在线%商城,电商,商品购买%系统demo,基于vscode,apache,html,css,jquery,php,mysql数据库
开发语言·前端·数据库·mysql·html·php·电商
草莓熊Lotso1 天前
C++ 方向 Web 自动化测试实战:以博客系统为例,从用例到报告全流程解析
前端·网络·c++·人工智能·后端·python·功能测试
星释1 天前
Rust 练习册 :Phone Number与电话号码处理
开发语言·机器学习·rust
one year.1 天前
Linux:线程同步与互斥
java·开发语言
一 乐1 天前
旅游|内蒙古景点旅游|基于Springboot+Vue的内蒙古景点旅游管理系统设计与实现(源码+数据库+文档)
开发语言·前端·数据库·vue.js·spring boot·后端·旅游
不爱编程的小九九1 天前
小九源码-springboot103-踏雪阁民宿订购平台
java·开发语言·spring boot
共享家95271 天前
LRU 缓存的设计与实现
开发语言·c++
夏鹏今天学习了吗1 天前
【LeetCode热题100(64/100)】搜索旋转排序数组
算法·leetcode·职场和发展