Algorithm
[알고리즘] 문자열 분석 백준 10820 (Python)
가영리
2022. 1. 17. 01:30
ASCII CODE 값
'A' ~ 'Z' : 65 ~ 90
'a' ~ 'z' : 97 ~ 122
0 ~ 9 : 48 ~ 57
코드
import sys
while True:
str = sys.stdin.readline().rstrip("\n")
if not str : break
alphabet =[0] * 4
for i in str:
if ord(i) > 96 and ord(i) < 123 :
alphabet[0] += 1
elif ord(i) > 64 and ord(i) < 91 :
alphabet[1] += 1
elif ord(i) > 47 and ord(i) < 58 :
alphabet[2] += 1
elif i == " " :
alphabet[3] += 1
print(*alphabet)
str = sys.stdin.readline().rstrip("\n")
개행을 무시하기 위해 rstrip("\n")
if not str : break
처음에 반복문 탈출 조건을 추가하지 않았더니 출력초과가 나왔다. 그래서 반복문 탈출 조건을 추가하여 문제를 풀 수 있었다.
입출력