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 인 것을 활용하시기도...
'공부 > 알고리즘' 카테고리의 다른 글
[알고리즘][백준] 11655번 ROT13 - 파이썬(python) 풀이 (0) | 2024.02.27 |
---|---|
[알고리즘][백준] 10820번 문자열 분석 - 파이썬(python) 풀이 (1) | 2024.02.27 |
[알고리즘][백준] 1918번 후위 표기식 - 파이썬(python) 풀이 (0) | 2024.02.26 |
[알고리즘][백준] 1935번 후위 표기식2 - 파이썬(python) 풀이 (1) | 2024.02.25 |
[알고리즘][백준] 17299번 오등큰수 - 파이썬(python) 풀이 (1) | 2024.02.25 |