fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void solve() {
  5. string s, t;
  6. cin>>s>>t;
  7.  
  8. /*
  9.   * len stores the length of the prefix of S already found.
  10.   * pos stores the current index in T.
  11.   */
  12. int len = 0, pos=0;
  13. while(len<s.length() && pos<t.length()) {
  14.  
  15. /* if the letter at position len matches. */
  16. if(s[len]==t[pos]) {
  17. len++;
  18. }
  19.  
  20. pos++;
  21. }
  22.  
  23. cout<<len<<endl;
  24. }
  25. int main() {
  26. solve();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3416KB
stdin
digger
biggerdiagram
stdout
3