-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathE0066.cpp
48 lines (44 loc) · 958 Bytes
/
E0066.cpp
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
/*
Problem Statement: https://www.hackerrank.com/challenges/weighted-uniform-string/problem
*/
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
vector<string> weightedUniformStrings(string s, vector<int> queries) {
vector<string> results;
unordered_set<int> weights;
int weight = s[0] - 'a' + 1;
weights.insert(weight);
for(int i=1 ; i<s.size() ; i++){
if(s[i] != s[i-1])
weight = 0;
weight += s[i] - 'a' + 1;
weights.insert(weight);
}
for(int i=0 ; i<queries.size() ; i++){
if(weights.find(queries[i]) != weights.end())
results.push_back("Yes");
else
results.push_back("No");
}
return results;
}
int main()
{
int n, num;
string s;
vector<int> x;
vector<string> results;
getline(cin, s);
cin>>n;
for(int i=0 ; i<n ; i++){
cin>>num;
x.push_back(num);
}
results = weightedUniformStrings(s, x);
for(string &result : results)
cout<<result<<endl;
return 0;
}