洛谷题单3-P5718 【深基4.例2】找最小值-python-流程图重构

题目描述

给出 n n n 和 n n n 个整数 a i a_i ai,求这 n n n 个整数中最小值是什么。

输入格式

第一行输入一个正整数 n n n,表示数字个数。

第二行输入 n n n 个非负整数,表示 a 1 , a 2 ... a n a_1,a_2 \dots a_n a1,a2...an,以空格隔开。

输出格式

输出一个非负整数,表示这 n n n 个非负整数中的最小值。

输入输出样例

输入

复制代码
5
5 7 4 2 6

输出

复制代码
2

说明/提示

数据保证, n ≤ 100 n\le100 n≤100 且 0 ≤ a i ≤ 1000 0\le a_i \le 1000 0≤ai≤1000。

方式

代码

python 复制代码
class Solution:
    @staticmethod
    def oi_input():
        """从标准输入读取数据"""
        num = int(input())
        nums = map(int, input().split())
        return num, nums

    @staticmethod
    def oi_test():
        """提供测试数据"""
        return 5, [5, 7, 4, 2, 6]

    @staticmethod
    def solution(num, nums):
        print(min(nums))


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

if __name__ == '__main__':
    num, nums = oi_test()
    # num, nums = oi_input()
    solution(num, nums)

流程图

结果输出 数据处理 打印结果
print(min_value) 忽略num参数 调用solution方法 计算最小值
min_value = min(nums) 开始 主函数调用 读取输入num
num = int(input()) 读取输入列表
nums = map(int, input().split()) 结束

相关推荐
苦夏木禾20 分钟前
js请求避免缓存的三种方式
开发语言·javascript·缓存
胡耀超23 分钟前
标签体系设计与管理:从理论基础到智能化实践的综合指南
人工智能·python·深度学习·数据挖掘·大模型·用户画像·语义分析
重庆小透明25 分钟前
力扣刷题记录【1】146.LRU缓存
java·后端·学习·算法·leetcode·缓存
超级土豆粉29 分钟前
Turndown.js: 优雅地将 HTML 转换为 Markdown
开发语言·javascript·html
desssq1 小时前
力扣:70. 爬楼梯
算法·leetcode·职场和发展
博观而约取1 小时前
Django 数据迁移全解析:makemigrations & migrate 常见错误与解决方案
后端·python·django
clock的时钟1 小时前
暑期数据结构第一天
数据结构·算法
wei_shuo2 小时前
飞算 JavaAI 开发助手:深度学习驱动下的 Java 全链路智能开发新范式
java·开发语言·飞算javaai
熊猫钓鱼>_>2 小时前
用Python解锁图像处理之力:从基础到智能应用的深度探索
开发语言·图像处理·python
蛋仔聊测试2 小时前
Playwright 中特定的 Fixtures
python