Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Given a string s, the task is to count number of subsequences of the form aibjck, where i >= 1, j >=1 and k >= 1.
- #include <iostream>
- using namespace std;
- int main() {
- int i,j,t,n;
- cin>>t;
- while(t--)
- {
- string s;
- cin>>s;
- int a=0,b=0,c=0;
- for(i=0;i<s.length();i++)
- {
- if(s[i]=='a')a=1+2*a;
- else if(s[i]=='b')b=a+2*b;
- else c=b+2*c;
- }
- cout<<c<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment