-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweightedUniformString.cpp
40 lines (37 loc) · 1.12 KB
/
weightedUniformString.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {int n,q,sum;
string str;
cin>>str;
sum=str[0]-96;
cin>>n;
vector<int> vec;
for(int i=1;i<str.length();i++){
if(str[i]!=str[i-1]){
//cout<<"sum pushed back at "<<i<<" is "<<sum<<endl;
vec.push_back(sum);
sum=str[i]-96;
}
else { // cout<<"sum pushed back at "<<i<<" is "<<sum<<endl;
vec.push_back(sum);
sum=sum+str[i]-96;
}
}
vec.push_back(sum);
for(int i=0;i<n;i++){
cin>>q;
vector<int>::iterator it;
it=find(vec.begin(),vec.end(),q);
if(it!=vec.end()){
cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}