10871번: X보다 작은 수 (acmicpc.net)
10871번: X보다 작은 수
첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다.
www.acmicpc.net
갈고 닦은 코드
n, x = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
if a[i] < x:
print(a[i], end =" ")
덜효율적인 내코드
answer =[]
n, x = map(int, input().split())
a = list(map(int, input().split()))
for i in range(-1, n):
i += 1
if a[i] < x:
answer.append(a[i])
print(*answer, sep =' ')
그러나 리스트에서 브라켓 없애는 법을 배웠다 막줄 참고!
수가 하나일 때는 *(리스트) 만해도 된다.
여기 더 많은 방법이 나와있다.
5 Ways to Remove Brackets from List in Python - Python Pool
5 Ways to Remove Brackets from List in Python
We all know What is a list in python? Whenever we hear a word list. We will say it is a collection of elements separated by commas and enclosed within the
www.pythonpool.com
'Algorithm > Python' 카테고리의 다른 글
10951 파이썬: while문 예외처리 (0) | 2022.04.08 |
---|---|
2439 파이썬: 오른쪽 정렬하기 (0) | 2022.04.08 |
2752 파이썬: 오름차순 정렬하기 (0) | 2022.04.04 |
1550 파이썬 16진수를 10진수로 변환하기 (0) | 2022.04.03 |
10430 파이썬 한 줄에 하나씩 출력하기 (0) | 2022.04.02 |
댓글