首页 > 学院 > 开发设计 > 正文

POJ - 1936 All in All解题报告

2019-11-08 18:42:56
字体:
来源:转载
供稿:网友
题目大意:

多组测试数据,每一组队两个字符串s和t。让你判断s是否为t的子序列。字符串长度100,000。这个时间复杂度肯定是O(n)了。

#include<iostream>#include<string.h>#include<stdio.h>#define N 100500using namespace std;char s[N]={0};char t[N]={0};void ceshi(){	for(int i=0;i<strlen(s);i++)	{		cout<<s[i];	}	for(int i=0;i<strlen(t);i++)	{		cout<<t[i];	}}int main(){	while(scanf("%s %s",s,t)!=EOF)	{		//ceshi();		int x=strlen(s);		int y=strlen(t);		int i=0,j=0;//i指s,j指t		while(1)		{			if(s[i]==t[j])			{				i++;			}			j++;			if(i>=x)			{				PRintf("Yes/n");				break;			}			if(j>=y)			{				printf("No/n");				break;			}		}			}}

注意:strlen是每一次都要重新遍历一遍数组 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表