ZOJ 3643:Keep Deleting
来源:互联网 发布:json入门 编辑:程序博客网 时间:2024/06/05 09:38
传送门: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;}
- zoj 3643 Keep Deleting
- ZOJ 3643 - Keep Deleting
- ZOJ 3643:Keep Deleting
- zoj 3643 Keep Deleting
- ZOJ-3643-Keep Deleting【字符串】
- ZOJ3643 Keep Deleting
- 字符串处理Keep Deleting
- zoj 2186 Keep on Truckin'
- ZOJ 2186 Keep on Truckin'
- zoj 2186 Keep on Truckin'
- ZOJ 2186 Keep on Truckin'
- ZOJ 2186 Keep on Truckin'
- ZOJ - 2186 Keep on Truckin'
- ZOJ Problem Set - 2186 Keep on Truckin'
- keep
- ZOJ Problem Set - 2186 Keep on Truckin'【模拟】
- Deleting Logs
- Deleting Clients
- linux下删除某一个目录及自身的bash脚本
- C语言中的整数自动转换原则
- 打破百度产品盘踞首位的神话
- Android UI LinearLayout线性布局
- 系统设计之初应该考虑到的问题
- ZOJ 3643:Keep Deleting
- 结合三层,使用存储过程与JQ实现下拉框的联动
- 浅谈触发器
- 常用代码片段
- EM算法推导过程
- 前正试图将类Kinect功能添加到未来Windows Phone
- hibernate sessionFactory是做什么的,一级缓存二级缓存都是干什么的
- 统治世界的十大算法
- jedis +springdata spring-data-redis 1.1.1 to 1.2.0 afterPropertiesSet signature exception