백준 - 심화2(python)

지환·2023년 8월 12일
0

백준(python)

목록 보기
8/67

출처 | https://www.acmicpc.net/step/52

1157 - 단어공부

words = input().upper()
unique_words = list(set(words))
cnt_list = []

for x in unique_words:
    cnt = words.count(x)
    cnt_list.append(cnt)
    
if cnt_list.count(max(cnt_list)) > 1:
    print("?")
    
else:
    max_index = cnt_list.index(max(cnt_list))
    print(unique_words[max_index])

2941 - 크로아티아 알파벳

croatia = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=']
word = input()

for i in croatia :
    word = word.replace(i, '*')  # input 변수와 동일한 이름의 변수
print(len(word))

1316번 - 그룹 단어 체커

N = int(input())
cnt = N

for i in range(N):
    word = input()	
    for j in range(0, len(word)-1):
        if word[j] == word[j+1]:
            pass
        elif word[j] in word[j+1:]:
            cnt -= 1
            break

print(cnt)
n = int(input())

group_word = 0
for _ in range(n):
    word = input()
    error = 0
    for index in range(len(word)-1):  # 인덱스 범위 생성 : 0부터 단어개수 -1까지 
        if word[index] != word[index+1]:  # 연달은 두 문자가 다른 때,
            new_word = word[index+1:]  # 현재글자 이후 문자열을 새로운 단어로 생성
            if new_word.count(word[index]) > 0:  # 남은 문자열에서 현재글자가 있있다면
                error += 1  # error에 1씩 증가.
    if error == 0:  
        group_word += 1  # error가 0이면 그룹단어
print(group_word)

25206번 - 너의 평점은

grade_mapping = {
    'A+': 4.5, 'A0': 4.0, 'B+': 3.5, 'B0': 3.0,
    'C+': 2.5, 'C0': 2.0, 'D+': 1.5, 'D0': 1.0, 'F': 0
}

total = 0
result = 0
for _ in range(20):
    s, p, g = input().split()
    p = float(p)
    if g != 'P':
        total += p
        result += p * grade_mapping[g]

if total != 0:
    print('%.6f' % (result / total))
profile
아는만큼보인다.

0개의 댓글