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

相关推荐
枫叶丹431 分钟前
【Qt开发】多元素类控件(三)-> QTreeWidget
开发语言·数据库·c++·qt
晨非辰35 分钟前
【数据结构入坑指南】--《层序分明:堆的实现、排序与TOP-K问题一站式攻克(源码实战)》
c语言·开发语言·数据结构·算法·面试
hansang_IR1 小时前
【题解】P2217 [HAOI2007] 分割矩阵 [记忆化搜索]
c++·数学·算法·记忆化搜索·深搜
洲覆1 小时前
Redis 驱动适配 Reactor 模式
开发语言·网络·数据库·redis
fl1768311 小时前
基于matlab实现的DnCNN网络
开发语言·matlab
第二层皮-合肥1 小时前
如何设置等长的最大走线长度
服务器·开发语言·php
程序员爱钓鱼1 小时前
Python编程实战 · 基础入门篇 | 类型转换与输入输出
后端·python
程序员爱钓鱼1 小时前
Python编程实战 · 基础入门篇 | 运算符详解
后端·python·编程语言
掘根1 小时前
【Protobuf】proto3语法详解1
开发语言·前端·javascript
Lee_yayayayaya1 小时前
《通信之道—从微积分到5G》阅读笔记
开发语言·matlab