[BOJ] 2562: μ΅œλŒ“κ°’

ohhj1999Β·2021λ…„ 7μ›” 29일
0

[BOJ] Algorithm Solving

λͺ©λ‘ 보기
14/62
post-thumbnail

πŸ”’ 예제

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

85
8

πŸ”§ 풀이

1. n = [int(sys.stdin.readline().rstrip()) for _ in range(10)]
2. max, index ν™œμš©

πŸ”‘ λ‹΅μ•ˆ

import sys

n = [int(sys.stdin.readline().rstrip()) for _ in range(9)]
val = max(n)
print(val)

idx = n.index(val) + 1
print(idx)

πŸ’‘ κ°œλ…

### max: return max value
n = [20, 230, 2, 1, 230]
val = max(n)		# κ°€μž₯ λ¨Όμ € λ§Œλ‚œ μ΅œλŒ“κ°’
print(val)			# 230

### index: return index of its value
idx = n.index(val)
print(idx)			# 1 

idx = n.index(0)	# μ—†λŠ” 값을 찾고자 ν•  경우, value error

### find: return index of its value in string
idx = n.find(val)	# λ¦¬μŠ€νŠΈμ—μ„œ 찾고자 ν•  경우, attribute error

s = 'hello world'
idx = s.find('o')
print(idx)			# 4
idx = n.find('a')	
print(idx)			# -1

0개의 λŒ“κΈ€