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

相关推荐
u***324317 小时前
使用python进行PostgreSQL 数据库连接
数据库·python·postgresql
mit6.82419 小时前
bfs|栈
算法
青瓷程序设计19 小时前
动物识别系统【最新版】Python+TensorFlow+Vue3+Django+人工智能+深度学习+卷积神经网络算法
人工智能·python·深度学习
tobebetter952719 小时前
How to manage python versions on windows
开发语言·windows·python
F_D_Z20 小时前
数据集相关类代码回顾理解 | sns.distplot\%matplotlib inline\sns.scatterplot
python·深度学习·matplotlib
9***P33420 小时前
PHP代码覆盖率
开发语言·php·代码覆盖率
daidaidaiyu20 小时前
一文入门 LangGraph 开发
python·ai
CoderYanger20 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz21 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
稚辉君.MCA_P8_Java21 小时前
DeepSeek 插入排序
linux·后端·算法·架构·排序算法