#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#define maxlen 100009
char sz1[maxlen];
char sz2[maxlen];
using namespace std;
int main()
{
while (scanf("%s%s",sz1,sz2)>0)
{
queue<char> myqueue ;
int nLen1 = strlen(sz1);
int nLen2 = strlen(sz2);
string s2(sz2);
int j=0;
for (int i=0;i<nLen1;i++)
myqueue.push(sz1[i]);
while(!myqueue.empty())
{
char temp = myqueue.front();
size_t found = s2.find(temp);
if (found != string::npos)
{
s2 = s2.substr(found+1);
myqueue.pop();
}
else
{
printf("No/n");
break;
}
}
if(myqueue.empty())
printf("Yes/n");
}
return 0;
}
本文介绍了一种使用队列和字符串查找方法来实现特定字符串匹配的算法。该算法通过将输入的第一个字符串的字符依次压入队列,并尝试从第二个字符串中找到对应的字符并移除,最终判断两个字符串是否能完全匹配。
300

被折叠的 条评论
为什么被折叠?



