poj1936 明明用string find的水题,wa了几次。。

//最长公共字串 不能少于3种base 我表示很不爽,为了输入的形式WA了四五遍。 
#include 
#include 
using namespace std;
int stack[100005];
string a, b;
int main()
{
	while (getline(cin, a, ' '))
	{
		getline(cin, b);
		memset(stack, -1, sizeof(stack));
		if (a.length() <= b.length())
		{
			int j = -1;
			for (int i = 0; i < a.length(); i++)
			{
				j = b.find(a[i], j + 1);
				stack[i] = j;
				//cout << j << endl;
				if (j == -1)
					break;
			}
			bool ok = true;
			bool ok2 = true;
			for (int i = 0; i < a.length(); i++)
			{
				if (stack[i] == -1)
				{
					ok = false;
					break;
				}
			}
			for (int i = 0; ok && i < a.length() - 1; i++)
			{
				if (stack[i] >= stack[i + 1])
				{
					ok2 = false;
					break;
				}
			}
			if (ok && ok2)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		}
		else
			cout << "No" << endl;
	}
	return 0;
}

你可能感兴趣的:(POJ水水水)