1. 程式人生 > >判斷一個字串是否為另外一個字串的子串

判斷一個字串是否為另外一個字串的子串

#include<iostream>
#include<string>
using namespace std;

bool checkchild(string &s, string &t)
{
	int j = 0;
	for (int i = 0; i < t.size(); i++)
	{
		while (j < s.size() && t[i] != s[j])
			j++;
		
		if (j == s.size())
			return false;

	}
	return true;
}

int main(int argc, char* argv[])
{
	string s, t;
	while (cin>>s>>t)
	{
		if (checkchild(s,t))
			cout << "Yes" << endl;

		else
			cout << "No" << endl;

	}
	
	return 0;
}
結果測試: