백준 - 1차원 배열

2022. 11. 12. 16:43백준 - Python

728x90

백준의 1차원 배열 문제들을 python으로 풀이한 것입니다.

1. 개수 세기

n = int(input())
nList = list(map(int, input().split()))
find = int(input())

print(nList.count(find))

성공

2. x보다 작은 수

n, x = map(int, input().split())
nList = list(map(int, input().split()))

for i in nList:
    if i < x:
        print(i, end=' ')

성공

3. 최소, 최대

n = int(input())
nList = list(map(int, input().split()))

print(max(nList), min(nList))

성공

4. 최댓값

nList = []
for i in range(9):
    nList.append(int(input()))
print(max(nList))
print(nList.index(max(nList)) + 1)

성공

5. 과제 안 내신 분..?

sList = [0] * 31

for i in range(28):
    sList[int(input())] = 1
    
for i in range(1, 31):
    if not sList[i]:
        print(i)

성공

6. 나머지

nList = []

for i in range(10):
    n = int(input())
    nList.append(n % 42)
    
nList = set(nList)
print(len(nList))

성공

7. 평균

n = int(input())
scores = list(map(int, input().split()))
m = max(scores)

for i in range(n):
    scores[i] = scores[i] / m * 100
    
print(sum(scores) / n)

성공

8. OX퀴즈

n = int(input())

for i in range(n):
    result = list(input())
    oState = False
    score = 0
    plus = 1
    for j in range(len(result)):
        if result[j] == 'O':
            if not oState:
                score += 1
                plus += 1
                oState = True
            else:
                score += plus
                plus += 1
        else:
            plus = 1
    print(score)

성공

9. 평균은 넘겠지

c = int(input())

for i in range(c):
    s = list(map(int, input().split()))
    avg = sum(s[1:]) / s[0]
    p = 0
    for j in range(1, s[0] + 1):
        if s[j] > avg:
            p += 1
    print('{0:0.3f}%'.format(p / s[0] * 100))

성공

 

728x90

'백준 - Python' 카테고리의 다른 글

백준 - 2차원 배열  (0) 2022.11.12
백준 - 문자열  (1) 2022.11.12
백준 - 반복문  (0) 2022.11.12
백준 - 조건문  (0) 2022.11.12
백준 - 입출력과 사칙연산  (0) 2022.11.12