POJ3302 Subsequence
来源:互联网 发布:利用热力学数据估算溴 编辑:程序博客网 时间:2024/06/16 03:46
Description
Given a string s of length n, a subsequence of it, is defined as another string s' = su1su2...sum where 1 ≤ u1 < u2 < ... < um ≤ n 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
5arash aaharash hsrkick kkcA aa12340b b31
Sample Output
YESYESNONOYES
#include<stdio.h>#include<string.h>#define MAXC 105int isSub(char* a,char* b){int i,j,alen,blen;alen=strlen(a);blen=strlen(b);if(alen<blen) //前边的竟然小些return 0;//顺着j=0; for(i=0;i<alen;i++)if(a[i]==b[j])j++; //移到b下一个字符if(b[j]=='\0')return 1;//逆着j=blen-1;for(i=0;i<alen;i++)if(a[i]==b[j])j--;if(j==-1)return 1;return 0;}int main(){int n;int i,j;char a[MAXC],b[MAXC];scanf("%d",&n);if(n>0){for(i=0;i<n;i++){scanf("%s %s",a,b);if(isSub(a,b))printf("YES\n");elseprintf("NO\n");}}return 0;}
- POJ3302 Subsequence
- poj3302
- poj3302
- poj3302
- Subsequence
- Subsequence
- Subsequence
- subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- Subsequence
- erlang和as3 socket的二进制通信
- asp.net常用方法
- 追寻理想主义
- 查看oracle当前连接数
- 使用 JET模板的一些约定
- POJ3302 Subsequence
- mysql 的 if 简单介绍
- SAAS数据安全是问题吗?
- 计算二进制位中1的个数
- ssh 中使用c3p0 的连接池配置
- Qt开发环境之Mac OS部署
- C++堆、栈、自由存储区、全局/静态存储区和常量存储区
- 泛型知识点总结
- NSString与NSMutableString字符串操作:增、删、改字符串