-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ#16139.py
More file actions
32 lines (27 loc) · 742 Bytes
/
Copy pathBOJ#16139.py
File metadata and controls
32 lines (27 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import string
import sys
Word = sys.stdin.readline().strip()
N = int(sys.stdin.readline().strip())
# arr[i][j] i : alphabet, j : index
# arr[i] -> alphabet count list i : alphabet
arr =[]
def get_alphabet_count():
for alph in string.ascii_lowercase:
arr_sub = []
k = 0
for j in Word:
if j == alph:
k += 1
arr_sub.append(k)
arr.append(arr_sub)
def main():
for _ in range(N):
inputs = sys.stdin.readline().strip().split()
a, s, e = inputs[0] ,int(inputs[1]), int(inputs[2])
l = arr[ord(a)-97]
rv = l[e] - l[s]
if a == Word[s]:
rv += 1
sys.stdout.write(str(rv)+'\n')
get_alphabet_count()
main()