[ 백준 문제 2562 / 파이썬 ] 최댓값

2023. 2. 8. 11:23백준/파이썬

 

2562번: 최댓값

9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오. 예를 들어, 서로 다른 9개의 자연수 3, 29, 38, 12, 57, 74, 40, 85, 61 이 주어

www.acmicpc.net

9개의 서로 다른 자연수가 주어질 때, 이들 중 최댓값을 찾고 그 최댓값이 몇 번째 수인지를 구하는 프로그램을 작성하시오.

예를 들어, 서로 다른 9개의 자연수

3, 29, 38, 12, 57, 74, 40, 85, 61

이 주어지면, 이들 중 최댓값은 85이고, 이 값은 8번째 수이다.

 

 

리스트 원소 추가 메서드 세가지
.append(), insert(), extend() 비교

1. insert()
list_name.insert( index, element )

원하는 인덱스에 원소를 추가해줍니다.


2. append()
list_name.append(element)

리스트의 끝에 원소를 추가해줍니다.

3. extend()
list_name.extend(tuple or string or list)

리스트의 끝에 원소를 추가해줍니다.
튜플, 문자열, 리스트 등 iterable(반복가능한) 자료형을 원소로 추가해줄수있습니다.
 

Difference between Append, Extend and Insert in Python - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

 

리스트 메서드 
.index()
 
원하는 원소의 인덱스가 몇 번인지 알려줍니다.

 

나의 정답 :

import sys
input = sys.stdin.readline

num = []

for i in range(9):
   num.append(int(input()))

print(max(num))
print(num.index(max(num))+1)

 

이제는 import sys도, for 문도 꽤 자연스럽게 찾게 되는 것 같아요 !