1. 程式人生 > >poj 1936 All in All

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;
}