洛谷题单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 小时前
【从视频到数据集:焦糖玛奇朵的魔法工具使用说明】
人工智能·python·深度学习·学习·算法·yolo·音视频
Runawayliquor20 小时前
opbase:CANN 所有算子的公共地基
大数据·数据库·人工智能·算法
徐安安ye20 小时前
FlashAttention 为什么对序列长度这么“敏感”?
人工智能·算法
潜创微科技20 小时前
IT6520:USB‑C 转 MIPI 芯片方案 4K@120Hz 高清显示
c语言·开发语言
yangshicong21 小时前
第11章:结构化输出与数据提取 —— 让 AI 直接返回你想要的数据格式
数据库·人工智能·redis·python·langchain·ai编程
言之。21 小时前
【Python】免费的中文 AI 配音方案
开发语言·人工智能·python
Warson_L21 小时前
python dict key详解
python
天天进步20151 天前
Python全栈项目:从零手操一个高性能 API 网关
开发语言·python
Java面试题总结1 天前
java高频面试题(2026最新)
java·开发语言·jvm·数据库·spring·缓存
黎阳之光1 天前
黎阳之光:以视频孪生重构智能监盘,为燃机打造新一代智慧电厂大脑
大数据·人工智能·算法·安全·数字孪生