forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwght.cpp
More file actions
52 lines (47 loc) · 771 Bytes
/
wght.cpp
File metadata and controls
52 lines (47 loc) · 771 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
#include<iostream>
using namespace std;
void wgt_string(string str,int q[],int n){
int wgt[str.length()];
int k=0;
wgt[0] = str[0]- 'a' +1;
for(int i=1;i<str.length();i++){
if(str[i-1]==str[i]){
wgt[i] = wgt[i-1] + (str[i]- 'a'+1);
}else{
wgt[i] = str[i]- 'a'+1;
}
}
//display
// for(int i=0;i<str.length();i++)
// cout<<wgt[i]<<" ";
string res[n];
int p=0;
for(int i=0;i<n;i++){
int flag=0;
for(int j=0;j<str.length();j++){
if(q[i] == wgt[j]){
flag=1;
res[p] = "Yes";
p++;
break;
}
}
if(flag==0){
res[p] = "No";
p++;
}
}
//display
for(int i=0;i<p;i++)
cout<<res[i]<<"\n";
}
int main(){
string str;
cin>>str;
int n;
cin>>n;
int q[n];
for(int i=0;i<n;i++)
cin>>q[i];
wgt_string(str,q,n);
}