poj3302

字符串处理简单题,注意reverse()的使用,这个函数要包含"algorithm"

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

bool work(string &st1, string st2)
{
	int i = 0, j = 0;
	while (st1[i] != '\0' && st2[j] != '\0')
	{
		if (st1[i] == st2[j])
			j++;
		i++;
	}
	if (j < st2.length())
		return false;
	return true;
}

int main()
{
	//freopen("D:\\t.txt", "r", stdin);
	int t;
	scanf("%d", &t);
	while (t--)
	{
		string st1, st2;
		cin >> st1 >> st2;
		if (work(st1, st2))
		{
			printf("YES\n");
			continue;
		}
		reverse(st2.begin(), st2.end());
		if (work(st1, st2))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

原文地址:https://www.cnblogs.com/rainydays/p/1948630.html