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

相关推荐
心念枕惊9 分钟前
PHP 在领域驱动(DDD)设计中的核心实践
android·开发语言·php
圣光SG11 分钟前
Java操作题练习(二)
java·开发语言·python
m0_6174939412 分钟前
Python OpenCV 分水岭算法(Watershed)详解与实战
python·opencv·算法
海带紫菜菠萝汤13 分钟前
企业批量PDF翻译方案:从选型到部署的完整指南
人工智能·算法·pdf
Sammyyyyy14 分钟前
如何利用本地技术栈构建 0 成本 AI SaaS 雏形
开发语言·人工智能·python·ai·servbay
AAIshangyanxiu18 分钟前
Python 机器学习与深度学习气象水文海洋全域应用技术体系:地学时空数据 AI 建模、数值模式后处理、气象海洋水文智能预测与数据处理
人工智能·python·机器学习·水文气象·气象预测·气象海洋
中微极客25 分钟前
边缘AI实战:TinyML模型量化与部署全解析(TensorFlow 2.18.0 + ESP32)
人工智能·python·tensorflow
贵慜_Derek28 分钟前
vLLM-05|MLA、Compressor、Indexer 与 SWA:Flash 注意力栈在 vLLM 里怎么落地
人工智能·算法·llm
冻柠檬飞冰走茶30 分钟前
PTA基础编程题目集 7-13 日K蜡烛图(C语言实现)
c语言·开发语言·数据结构·算法
csdn_aspnet37 分钟前
C# 从凸包中删除点(Deleting points from Convex Hull)
开发语言·c#