HDU 4150 Powerful Incantation

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4150

题目意思很简单,就是在字符串a中包含多少组不能重复的字符串b,直接暴力搜索;

在定义字符串这里wa了几下,唉,英语不行,(length<=10^6),a要开到百万位。

代码:

#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000001],b[100001];
	int s,i,j,p,count,len1,len2;
	scanf("%d",&s);
	while(s--)
	{
		count=0;
		scanf("%s %s",a,b);
		len1=strlen(a);
		len2=strlen(b);
		for(i=0;i<=len1-1;i++)
		{
			p=i;
			for(j=0;j<=len2-1;j++)
			{
				if(a[p]==b[j]) {p++;}
				else
					break;
			}
			if(j==len2)
			{
				count++;
				i=i+len2-1;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

再贴一段错误代码,考试完在再想吧,先留在这里,免的忘了,考试要紧

#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000001],b[100001];
	int s,i,j,p,len1,len2,count;
	scanf("%d",&s);
	while(s--)
	{
		getchar();
		scanf("%s %s",a,b);
		len1=strlen(a);
		len2=strlen(b);
		p=0;count=0;
		while(p<=len1)
		{
			i=p;j=0;
			while(a[i]==b[j])
			{i++;j++;}
			if(j==len2)
			{
				count++;
				continue;
			}
			else
				p++;
		}
		printf("%d\n",count);
	}
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值