传送门: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
#include
#include
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=lenA && strcmp(&stack[top-lenA],a)==0)
{
count++;
top-=lenA;
}
}
printf("%d\n",count);
}
return 0;
}