ZZULI_SummerPractice(4)nbsp;POJnbsp;3302…

2023-10-20 03:58

本文主要是介绍ZZULI_SummerPractice(4)nbsp;POJnbsp;3302…,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Subsequence
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 6570Accepted: 3829

Description

Given a string s of length n, a subsequence of it, is defined as another string s' = su1su2...sum where 1 ≤ u1 < u2 < ... < umn and si is the ith character of s. Your task is to write a program that, given two strings s1 and s2, checks whether either s2 or its reverse is a subsequence of s1 or not.

Input

The first line of input contains an integer T, which is the number of test cases. Each of the next T lines contains two non-empty strings s1 and s2 (with length at most 100) consisted of only alpha-numeric characters and separated from each other by a single space.

Output

For each test case, your program must output "YES", in a single line, if either s2 or its reverse is a subsequence of s1. Otherwise your program should write "NO".

Sample Input

5
arash aah
arash hsr
kick kkc
A a
a12340b b31

Sample Output

YES
YES
NO
NO
YES

Source

Amirkabir University of Technology Local Contest 2006
题比较简单,就是从第一个字符串中按顺序看看能不能找到第二个字符串的字母,或者第二个字符串倒置后的字母。
代码:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,len;
char str1[102],str2[102],str[102];
scanf("%d",&n);
while(n--)
{
scanf("%s%s",str1,str2);
len=strlen(str1);
j=0;
for(i=len-1;i>=0;i--)
str[j++]=str1[i];
str[j]=0;
i=j=0;
while(str2[i]!=0)
{
if(str1[j]==str2[i]){i++;j++;}
else j++;
if(str1[j]==0)break;
}
if(str2[i]==0)
printf("YES\n");
else{
i=j=0;
while(str2[i]!=0)
{
if(str[j]==str2[i]){i++;j++;}
else j++;
if(str[j]==0)break;
}
if(str2[i]==0)printf("YES\n");
else printf("NO\n");
}
}
return 0;
}

这篇关于ZZULI_SummerPractice(4)nbsp;POJnbsp;3302…的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/244490

相关文章

Ubuntunbsp;出现apt-get:nbsp;Packag…

学习了 原文地址:Ubuntu 出现apt-get: Package has no installation candidate问题 作者:zhou4539   Ubuntu 出现apt-get: Package has no installation candidate问题 分类: 系统-Linux 2011-12-18 13:32 751人阅读 评论(0) 收藏 举报 今天在

微信公众平台nbsp;10.29日更新nbsp;之己见

曾经有前辈说过,无论微信 5.0 的部分功能做的有多差,但是这是微信转型的一个里程碑。起初,笔者有点不太理解其中的道理,但是随着自己做了些东西东西后,才慢慢发现,这种先推广后优化,让用户去引导功能开发的策略是多么的明智。 此前,网络曾有谣言,微信服务号将于明年起收3000元/年的年费,这一传言尚未被证实,昨天微信公众平台正式推出了微信认证这一个功能,服务号可以花费300元进行认

C语言的条件编译#if,nbsp;#elif…

原文地址:C语言的条件编译#if, #elif, #else, #endif、#ifdef, #ifndef 作者:Embeder 有些程序在调试、兼容性、平台移植等情况下可能想要通过简单地设置一些参数就生成一个不同的软件,这当然可以通过变量设置,把所有可能用到的代码都写进去,在初始化时配置,但在不同的情况下可能只用到一部分代码,就没必要把所有的代码都写进去,就可以用条件编译,通过预编译指

结构体定义nbsp;typedefnbsp;structnbsp;…

很不错 原文地址:结构体定义 typedef struct 用法详解和用法小结 作者:紫心玲儿 typedef是类型定义的意思。typedef struct 是为了使用这个结构体方便。 具体区别在于: 若struct node {}这样来定义结构体的话。在申请node 的变量时,需要这样写,struct node n; 若用typedef,可以这样写,typedef struct node

C++nbsp;usingnbsp;namespacenbsp;stdnbsp;详解

一 : 和是不一样,前者没有后缀,实际上,在你的编译器include文件夹里面可以看到,二者是两个文件,打开文件就会发现,里面的代码是不一样的。  后缀为.h的头文件c++标准已经明确提出不支持了,早些的实现将标准库功能定义在全局空间里,声明在带.h后缀的头文件里,c++标准为了和C区别开,也为了正确使用命名空间,规定头文件不使用后缀.h。  因此,当使用时,相当于在c中调用库函数,使用

C++的dllexport和dllimportnbsp;nbsp;…

C++的dllexport和dllimport: __declspec(dllexport) 声明一个导出函数,是说这个函数要从本DLL导出。我要给别人用。一般用于dll中省掉在DEF文件中手工定义导出哪些函数的一个方法。当然,如果你的DLL里全是C++的类的话,你无法在DEF里指定导出的函数,只能用__declspec(dllexport)导出类 __declspec(dllimport)

#ifndefnbsp;PRINT_Hnbsp;nbsp;…

例一: print.h: 文件内容 #ifndef PRINT_H #define PRINT_H #ifdef __cplusplus extern " C " { #endif  //打印点东西 void Print(int iNum);  #ifdef __cplusplus }#endif  #endif 作用:为了防止头文件被重复包含: 如头文件a.h中包含函数f

templatenbsp;lt;nbsp;typenameamp;nb…

template < typename var_name >:定义一个模板函数 var_name表示一个类型;在模版实例化时可以替换任意类型,不仅包括内置类型(int等),也包括自定义类型class。 比如你想求2个int  float  或double型变量的值,只需要定义这么一个函数就可以了,假如不用模板的话,你就必须针对每种类型都定义一个sum函数.. int sum(int, int);

OpenGL-ESnbsp;中的nbsp;mipmappingnbsp;…

原文地址:OpenGL-ES 中的 mipmapping 算法 作者:雁子     最近刚把mipmapping在ES中实现完成,在这里想总结一下算法,并讨论一下相关的结果。     Mipmap在3D图形学中主要是用来做anti-aliasing,这跟图像学中的概念是一致的:图像在缩小时因为采样率不够,就会导致混叠现象,如果是线,就表现为断线,如果是纹理比较复杂,就表现为纹理变得杂乱。

Cygwinnbsp;amp;nbsp;Gitnbsp;中文支持

原文地址:Cygwin & Git 中文支持 作者:CICO李依洁 1.在下面的文件末尾添加一行。 C:cygwinhomecico.bash_profile export LESSCHARSET=latin1 ps:控制源代码(例如java文件)在Cygwin界面输出时,不做特殊处理(不要用UTF-8的规则将字节拼成字,utf-8用三个字节解释汉字,GBK用两个字节)。 2.打