第3章-7.字符转换 (20分)

本题要求编写程序,找出给定的n个数中的最大值及其对应的最小下标(下标从0开始)。

输入格式:

输入在第一行中给出一个正整数n(1)。第二行输入n个整数,用空格分开。

输出格式:

在一行中输出最大值及最大值的最小下标,中间用一个空格分开。

输入样例:

6
2 8 10 1 9 10
 

输出样例:

10 2
 1 # 求最大值及其下标 (20分)
 2 # Author: cnRick
 3 # Time  : 2020-3-25
 4 # 数据预处理
 5 n = int(input())
 6 nums_list = input().split()
 7 for i in range(n): #把数字字符串转为整型
 8     nums_list[i] = int(nums_list[i])
 9 max_num = max(nums_list) #求列表中的最大值
10 max_num_index = nums_list.index(max_num) #求列表中最大值的下标
11 print(f"{max_num} {max_num_index}")
 
原文地址:https://www.cnblogs.com/dreamcoding/p/12567439.html