BOJ_단계별로 풀어보기_4. 1차원 배열 (파이썬, Python)

창고·2022년 11월 21일
0

https://www.acmicpc.net/step/6

1. 개수 세기

a = int(input())
b = list(map(int, input().split()))
c = int(input())

print(b.count(c))

2. X보다 작은 수

a, b = list(map(int, input().split(' ')))
num_list = list(map(int, input().split(' ')))
blank_list = []
for num in num_list:
    if num < b:
        blank_list.append(str(num)) # 문자열로 변경
print(' '.join(blank_list))

3. 최소, 최대

import sys

a = int(input())
t_input = sys.stdin.readline
b = list(map(int, t_input().split(' ')))
max = max(b)
min = min(b)
print(min, max)

4. 최댓값 (확인 중)

5. 과제 안 내신 분 (확인 중)

6. 나머지

import sys

t_input = sys.stdin.readline
numbers = list()

for i in range(10):
    a = int(input())
    b = a % 42
    if b not in numbers:
        numbers.append(b)
        
print(len(numbers))

7. 평균

a = int(input())
b = list(map(int, input().split(' ')))
c = list()
total = 0

for i in range(a):
    c.append(b[i])
    total += b[i]

print(total / len(c) / max(c) * 100)

8. OX 퀴즈

b= int(input())
for i in range(b):
    a = str(input())
    score = 0
    cs = 0
    for i in range(len(a)):
        if a[i] == "O":
            cs += 1
            score += cs
        else:
            cs = 0
            score += cs
    print(score)

9. 평균은 넘겠지

a = int(input())
rlist = list()
for i in range(a):
    b = list(map(float, input().split(' ')))
    ct = 0
    av = (sum(b)-b[0]) / (b[0])
    for t in range(1, len(b)):
        if b[t] > av:
            ct += 1
    result = round((float(ct) / float(len(b)-1) * 100), 3)
    print("{:.3f}%".format(result))
        
profile
공부했던 내용들을 모아둔 창고입니다.

0개의 댓글