multi subsiquence word pattern matcher [closed]

  c++, java, pattern-matching, python

Parent’s love is eternal and so is the love for parents. In this fast moving world, we often forget to show our love and call "MOM" and "DAD". It is time to recall them as many times as possible in this challenge. In this challenge, you are given a string S and you have to determine the count of subsequences of "DAD" and "MOM" in the given string.

Note: The order of the sequence should be the same however letters don’t have to be consecutive.

Input Format
The only line of input consists of a string.
It is guaranteed that the string consists of only uppercase English letters.

Constraints
1<= |S| <=100000

Output Format
Print a single integer – the number of subsequences "DAD" and "MOM" in the string.

Sample TestCase 1
Input
MOMODAAMAD
Output
7
Explanation
There are 4 subsequences of MOM and 3 subsequences of DAD in the given string.

TIME LIMIT(X):
0.50 SEC(S) FOR EACH INPUT.
MEMORY LIMIT:
512 MB
SOURCE LIMIT:
100 KB
ALLOWED LANGUAGES:
C, C++, C++11, C++14, C#, JAVA, JAVA 8, KOTLIN, PHP, PHP 7, PYTHON, PYTHON 3, PERL, RUBY, NODE JS, SCALA, CLOJURE, HASKELL, LUA, ERLANG, SWIFT, VBNET, JS, OBJC, PASCAL, GO, F#, D, GROOVY, TCL, OCAML, SMALLTALK, COBOL, RACKET, BASH, GNU OCTAVE, RUST, COMMON LISP, R, JULIA, FORTRAN, ADA, PROLOG, ICON, ELIXIR, COFFEESCRIPT, BRAINFUCK, PYPY, LOLCODE, NIM, PICOLISP, PIKE, WHITESPACE, PYPY3

Source: Windows Questions C++

7 thoughts on - multi subsiquence word pattern matcher [closed]

  • Parent’s love is eternal and so is the love for parents. In this fast moving world, we often forget to show our love and call “MOM” and “DAD”. It is time to recall them as many times as possible in this challenge. In this challenge, you are given a string S and you have to determine the count of subsequences of “DAD” and “MOM” in the given string.

    Note: The order of the sequence should be the same however letters don’t have to be consecutive.

    Input Format
    The only line of input consists of a string.
    It is guaranteed that the string consists of only uppercase English letters.

    Constraints
    1<= |S| <=100000

    Output Format
    Print a single integer – the number of subsequences "DAD" and "MOM" in the string.

    Sample TestCase 1
    Input
    MOMODAAMAD
    Output
    7
    Explanation
    There are 4 subsequences of MOM and 3 subsequences of DAD in the given string.

    TIME LIMIT(X):
    0.50 SEC(S) FOR EACH INPUT.
    MEMORY LIMIT:
    512 MB
    SOURCE LIMIT:
    100 KB
    ALLOWED LANGUAGES:
    C, C++, C++11, C++14, C#, JAVA, JAVA 8, KOTLIN, PHP, PHP 7, PYTHON, PYTHON 3, PERL, RUBY, NODE JS, SCALA, CLOJURE, HASKELL, LUA, ERLANG, SWIFT, VBNET, JS, OBJC, PASCAL, GO, F#, D, GROOVY, TCL, OCAML, SMALLTALK, COBOL, RACKET, BASH, GNU OCTAVE, RUST, COMMON LISP, R, JULIA, FORTRAN, ADA, PROLOG, ICON, ELIXIR, COFFEESCRIPT, BRAINFUCK, PYPY, LOLCODE, NIM, PICOLISP, PIKE, WHITESPACE, PYPY3

  • Hi, That is a nice Question by the way, but can u please send me the answer I am trying it for a while to be honest but i could not get the answer if it possible so please send me the code on C++ or python whatever u want, Nice question by the way.

  • /*Enter your code here. Read input from STDIN. Print your output to STDOUT*/
    #include
    #define ll long long
    using namespace std;
    ll countsubsequence(string s1,string s2)
    {
    ll m=s1.size();
    ll n=s2.size();
    vector<vector >dp(m+1,vector(n+1));
    for(int i=0;i<=n;i++)
    dp[0][i]=0;
    for(int i=0;i<=m;i++)
    dp[i][0]=1;
    for(int i=1;i<=m;i++)
    {
    for(int j=1;j>s;
    ll ans=countsubsequence(s,”DAD”);
    ll mom=countsubsequence(s,”MOM”);
    // cout<<ans<<" "<<mom<<endl;
    cout<<ans+mom<<endl;
    }

LEAVE A COMMENT