问题 I: From S To T-----最暴力的方法!!!用题目意思直接做!!!!

题目描述

You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of s, in the end or between any two consecutive characters).
For example, if p is aba, and s is de, then the following outcomes are possible (the character we erase from p and insert into s is highlighted):
aba → ba, de → ade;
aba → ba, de → dae;
aba → ba, de → dea;
aba → aa, de → bde;
aba → aa, de → dbe;
aba → aa, de → deb;
aba → ab, de → ade;
aba → ab, de → dae;
aba → ab, de → dea;
Your goal is to perform several (maybe zero) operations so that s becomes equal to t. Please determine whether it is possible.
Note that you have to answer q independent queries.

 

输入

The first line contains one integer q (1≤q≤100) — the number of queries. Each query is represented by three consecutive lines.
The first line of each query contains the string s (1≤|s|≤100) consisting of lowercase Latin letters.
The second line of each query contains the string t (1≤|t|≤100) consisting of lowercase Latin letters.
The third line of each query contains the string p (1≤|p|≤100) consisting of lowercase Latin letters.

 

输出

For each query print YES if it is possible to make s equal to t, and NO otherwise.

样例输入

4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

 

样例输入

YES
YES
NO
NO

提示

In the first test case there is the following sequence of operation:
s= ab, t= acxb, p= cax;
s= acb, t= acxb, p= ax;
s= acxb, t= acxb, p= a.
In the second test case there is the following sequence of operation:
s= a, t= aaaa, p= aaabbcc;
s= aa, t= aaaa, p= aabbcc;
s= aaa, t= aaaa, p= abbcc;
s= aaaa, t= aaaa, p= bbcc.

一个字符串题目,本来没有想法,在涵大佬的提示下,得到了灵感,get到了自己的暴力枚举法hhhhh

思路都在代码注释

#include
#include
#include
#include
using namespace std;
char s[109],t[109],p[109];
int n,lens,lent,lenp,cnt1=0,cnt2=0;
bool vist[109];
bool visp[109];
int main()
{
    scanf("%d",&n);
    while(n--)
    {
        cnt1=0;
        cnt2=0;
        memset(vist,0,sizeof(vist));
        memset(visp,0,sizeof(visp));
        scanf("%s",s);
        scanf("%s",t);
        scanf("%s",p);	//思路:先从字符串t里面从前往后按顺序找s里的字符,若找到的匹配的个数与字符串s的长度不符, 
        lens=strlen(s);	//则说明s不是t一个子串,即存在字符属于s但是不属于t,即s和p怎么操作都有不匹配的地方 
        lent=strlen(t);	//若匹配到的字符个数与s长度相同,则说明s是t的一个子串,那么再从p里面匹配t中没有被标记过的字符, 
        lenp=strlen(p);	//查找可以没有顺序,因为可以随机插入,但是找到一个必须要在两个字符串中都要标记 ,最后两个被标记的和如果等于t的长度,则满足要求
       	int temp=0;	
		for(int i=0;i

 

你可能感兴趣的:(基础知识)