[python] 백준 단계별로 풀어보기 - 1차원 배열

Jubami·2022년 5월 16일
0

코테연습

목록 보기
6/19

백준 3052 나머지

서로 다른 나머지 갯수를 출력하기 -> set 이용

c = []
for num in range(10):  # 0부터 9까지
    a = int(input())
    b = a % 42
    c.append(b)
  
print(len(set(c)))

백준 1546 평균

n = int(input())  # 과목 수
test_list = list(map(int, input().split()))
max_score = max(test_list)

new_list =[]
for score in test_list:
  new_list.append(score/max_score *100)

score_avg = sum(new_list)/n

print(score_avg)

백준 8958 OX퀴즈

  • O가 연속되면 score를 1씩 증가시킴
  • X면 score을 다시 0으로 초기화 (else문)
import sys

input = sys.stdin.readline

n = int(input())

for _ in range(n):
    results = list(input())
    score = 0
    total_score = 0
    for result in results:
        if result == 'O':
            score += 1
            total_score += score
        else:
            score = 0
    print(total_score)

백준 4344 평균은 넘겠지

  • list[0] : 길이
  • list[1:] : 점수

avg로 평균 계산 후 if 문으로 점수가 avg보다 크면 cnt+=1

print는 포맷 스트링 사용해서 출력


import sys
input = sys.stdin.readline

n = int(input())

for _ in range(n):
    scores = list(map(int, input().split()))
    avg = sum(scores[1:]) / scores[0]
    count = 0
    for score in scores[1:]:
        if score > avg:
            count += 1

    rate = count / scores[0] *100
    print(f'{rate:.3f}%')

profile
LV.1 아밥퍼

0개의 댓글