-
[백준] 10820 문자열 분석Algorithm 2025. 8. 5. 22:35
[문제]
https://www.acmicpc.net/problem/10820
[풀이]import sys public class Solution { public static void main(String[] args) { lines = [] try: while True: line = input() if line == "": break lines.append(line) except EOFError: pass for l in lines: a, A, digit, space = 0, 0, 0, 0 for alpha in l: if alpha.isdigit(): digit +=1 if alpha.islower(): a += 1 if alpha.isupper(): A += 1 if alpha.isspace(): space +=1 print(a,A,digit,space) } }
[학습 포인트]
1. 입력값의 수가 정해지지 않았을 때 받는 방법
-- while 문을 사용한다.import sys while true: arr = sys.stdin.readline().rstrip('\n') if not arr: break
해당 방법은 1) 한줄씩 읽어와 2) 오른쪽 개행문자를 제거하고 3) 더 이상 읽어올 문자가 없으면 종료한다.
2. input() 과 sys.stdin.readline()의 차이
728x90'Algorithm' 카테고리의 다른 글
PriorityQueue (3) 2025.08.11 [백준] 1238 파티 (1) 2025.08.09 [백준] 11724_연결 요소의 개수 (0) 2022.08.23 [백준] 4963_섬의 개수 (0) 2022.08.23 [백준] 2468_안전 영역 (0) 2022.08.23