본문 바로가기
공부/알고리즘

[알고리즘][백준] 10808번 알파벳 개수 - 파이썬(python) 풀이

by 무명오리 2024. 2. 26.

https://www.acmicpc.net/problem/10808

 

10808번: 알파벳 개수

단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.

www.acmicpc.net


나의 코드
import sys

alpha = list("abcdefghijklmnopqrstuvwxyz")
num = [0] * 26

input = sys.stdin.readline().rstrip()

for i in input:
    num[alpha.index(i)] += 1

print(*num)

 

count를 활용해서도 가능하다!

import sys

alpha = list("abcdefghijklmnopqrstuvwxyz")
num = [0] * 26

input = sys.stdin.readline().rstrip()

for i in set(input):
    num[alpha.index(i)] = input.count(i)

print(*num)

다른 분들은 아스키코드 ord('a') = 97 인 것을 활용하시기도...