fork download
#include <iostream>
using namespace std;

void solve() {
    string s, t;
    cin>>s>>t;

    /*
     * len stores the length of the prefix of S already found.
     * pos stores the current index in T.
     */
    int len = 0, pos=0;
    while(len<s.length() && pos<t.length()) {

        /* if the letter at position len matches. */ 
        if(s[len]==t[pos]) {
            len++;
        }

        pos++;
    }

    cout<<len<<endl;
}
int main() {
	solve();
	return 0;
}
Success #stdin #stdout 0s 3416KB
stdin
digger
biggerdiagram
stdout
3