ZOJ 3643:Keep Deleting

传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3643

Time Limit: 2 Seconds      Memory Limit:  65536 KB

 

Assume that string A is the substring of string B if and only if we can find A in B, now we have a string A and another string B, your task is to find a A in B from B's left side to B's right side, and delete it from B till A is not a substring of B, then output the number of times you do the delete.

There are only letters(A-Z, a-z) in string A and B.

Input

This problem contains multiple test cases. Each case contains two line, the first line is string A, the second line is string B, the length of A is less than 256, the length of B is less than 512000.

Output

Print exactly one line with the number of times you do the delete for each test case.

Sample Input

abcd

abcabcddabcdababcdcd

 

Sample Output

5

 

Hint

abcabcddabcdababcdcd delete=0

abcdabcdababcdcd         delete=1

abcdababcdcd                 delete=2

ababcdcd                         delete=3

abcd                                 delete=4

                                         delete=5

 

 【从题目复制过来的hint根本不对齐让我的强迫症犯了手动对齐的→_→

 

 

 

 

题目都没看完就开始做了2333看了一下hint就大概知道要干嘛了

题目大意:把b中的元素一个个压栈,如果发现a是子串就把子串出栈。

字符串匹配的话看起来可以用KMP?反正渣渣不会QAQ比赛可以带纸质材料之前有打印过一堆算法其中是有KMP的,可惜还没理解照模板敲的话没什么意思,就直接用现成的函数反正过了没超时~由于不常用string.h的函数还把头文件忘了,函数名和作用根本对不上!先是用了strchr后来发现用错函数了QAQ

之后又看到了华丽丽的报错!

error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'!!!!!!

查了一下strcmp的源码之后才加上了&。。QAQ

【还有根本不知道匹配不匹配返回什么QAQ果然之前打印模板顺便把string.h函数的用法都存下来了的我真是机智!

 

今天fsk下正式通知了周五上机考试不用vector而是正常的数组简直太感动!QAQ所以我还是用数组刷题吧2333而且栈模拟正好就是期末考内容~

 

 

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	char a[256],b[512000],stack[51200];
	int i,count,lenA,lenB,top;
	while(scanf("%s%s",&a,&b)!=EOF)
	{
		i=0;
		count=0;
		top=0;
		lenA=strlen(a);
		lenB=strlen(b);
		while(i<lenB)
		{
			stack[top++]=b[i++];
			stack[top]='\0';
			if(top>=lenA && strcmp(&stack[top-lenA],a)==0)
			{
				count++;
				top-=lenA;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值