-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniform_weighted_string.py
More file actions
54 lines (40 loc) · 960 Bytes
/
uniform_weighted_string.py
File metadata and controls
54 lines (40 loc) · 960 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the weightedUniformStrings function below.
def weightedUniformStrings(s, queries):
dict1={}
dict2={}
n=len(s)
st=s[0]
wt=ord(s[0])-96
for i in range(1,n):
if s[i]==s[i-1]:
st=st+s[i]
wt=wt+ord(s[i])-96
else:
dict1[wt]=wt
st=s[i]
wt=ord(s[i])-96
if i==n-1:
dict1[wt]=wt
print(dict1)
result=[]
for i in range(len(queries)):
try:
res=dict1[queries[i]]
result.append("Yes")
except:
result.append("No")
return result
if __name__ == '__main__':
s = input()
queries_count = int(input())
queries = []
for _ in range(queries_count):
queries_item = int(input())
queries.append(queries_item)
result = weightedUniformStrings(s, queries)