A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, ifs=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.
However rather than being happy once, he loves twice as much being happy twice! So, when he got stringt as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.
Help s determine the number of distinct ways to cut the given stringt into two parts in the required manner.
The first line contains string s, consisting of lowercase English letters. The length of strings is from 1 to 1000 letters.
The second line contains string t, that also consists of lowercase English letters. The length of stringt is from 1 to 106 letters.
Print the sought number of ways to cut string t in two so that each part mades happy.
aba baobababbah
2
mars sunvenusearthmarsjupitersaturnuranusneptune
0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include <map>
#include <queue>
using namespace std;
//523C 间隔挡板问题
int main()
{
while(true)
{
string s1,s2;
int m,n;
int o,p;
int i,j;
cin>>s1>>s2;
m=s1.size();
n=s2.size();
o=0;
p=0;
for(i=0;i<n;i++)
{
if(s2[i]==s1[o])o++;
if(o==m)break;
}
for(j=n-1;j>=0;j--)
{
if(s2[j]==s1[m-1-p])p++;
if(p==m)break;
}
cout<<max(j-i,0)<<endl;
}
return 0;
}