Skip to content

Commit 2494ee8

Browse files
committed
[BOJ] #16139. 인간-컴퓨터 상호작용 / 실버1 / 60분 이상 / 힌트
1 parent eefa156 commit 2494ee8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
s = input().rstrip() # 문자열
5+
q = int(input()) # 질문 개수
6+
prefix_sum = [[0] * 26] # 누적합 리스트 초기화
7+
8+
# 입력한 문자열에 대한 누적합 구하기
9+
# ord(): 아스키코드 구하는 함수
10+
for i, ch in enumerate(s):
11+
prefix_sum.append(prefix_sum[len(prefix_sum) - 1][:]) # 직전 배열 복사(누적하여 저장 가능)
12+
prefix_sum[i+1][ord(ch) - 97] += 1 # 문자열 위치에서 해당 알파벳이 위치한 자리값 누적합
13+
14+
for _ in range(q):
15+
alpha, start, end = map(str, input().strip().split()) # 문자, 시작, 끝 입력
16+
## 구간합 구하기
17+
# 누적합 - 구간
18+
answer = prefix_sum[int(end)+1][ord(alpha)-97] - prefix_sum[int(start)][ord(alpha)-97]
19+
print(answer)

0 commit comments

Comments
 (0)