poj 1936 All in All

一道简单的字符串匹配问题,询问s1是否是s2的子串。
#include <iostream>
#include <string>
using namespace std;
void solve(string s1,string s2);
int main()
{
	string s1, s2;
	while (cin >> s1 >> s2)
	{
		solve(s1,s2);
	}
	//system("pause");
}
void solve(string s1, string s2)
{
	int i = 0;
	int j = 0;
	while (i!=s1.size()&&j!=s2.size())
	{
		if (s1[i] == s2[j])
		{
			i++;
			j++;
		}
		else
		{
			j++;
		}
	}
	if (i == s1.size())
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

你可能感兴趣的:(字符串匹配)