【题意简述】:如果正序的S2或者逆序的S2是S1的子序列,则输出“YES”,否则输出“NO”。
【分析】:模拟的这个思路就好了。
代码参考:http://www.cnblogs.com/baoluqi/p/3734361.html
//728K 0Ms
#include<iostream>
#include<cstring >
using namespace std;
string s1,s2;
bool yes(string s1,string s2)
{
int i= 0,j = 0;
while(s1[i] != '\0'&&s2[j] != '\0')
{
if(s1[i] == s2[j])
j++;
i++;
}
if(j<s2.length())
return false;
else
return true;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>s1>>s2;
if(yes(s1,s2))
{
cout<<"YES"<<endl;
continue;
}
reverse(s2.begin(),s2.end());// 积累!!
if(yes(s1,s2))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}