HDU 5414(2015多校10)-CRB and String(字符串处理)
2015-08-21 15:29
477 查看
题目地址:HDU 5414
题意:要求判断字符串s能否通过添加若干个字符得到字符串t
思路:这个题看起来复杂,其实仔细一分析,成功转化只包含两种情况。第一种因为要求插入的新字符和它前面的字符c不同,如果t中有x个连续的c,那么在s中也必须有x个连续的c;第二种是s必须是t的一个不连续子串。
题意:要求判断字符串s能否通过添加若干个字符得到字符串t
思路:这个题看起来复杂,其实仔细一分析,成功转化只包含两种情况。第一种因为要求插入的新字符和它前面的字符c不同,如果t中有x个连续的c,那么在s中也必须有x个连续的c;第二种是s必须是t的一个不连续子串。
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map> #include <bitset> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; const int inf=0x3f3f3f3f; const double pi= acos(-1.0); const double esp=1e-7; const int Maxn=1e5+10; char s[Maxn],t[Maxn]; int n,m; int len1,len2; int check() { int i,j; for(i=1;i<len2;i++) if(t[i]!=t[0]) break;//找到t串的第一个不连续的位置 for(j=0;j<i;j++)//看s的前i个子串是否连续 if(s[j]!=t[j]) return 0; for(;j<len1;){ for(;i<len2;i++){//找到下一个和s相等的地方 if(t[i]==s[j]) break; } if(i==len2) return 0;//如果t找完了还没跳出证明s不是t的子串 i++; j++; } return 1; } int main() { int T; scanf("%d",&T); while(T--){ scanf("%s %s",s,t); len1=strlen(s); len2=strlen(t); if(check()) puts("Yes"); else puts("No"); } return 0; }
相关文章推荐
- Android之Adapter用法总结
- LeetCode题解:Merge Two Sorted Lists
- android---创建自定义的view
- 数字游戏 2135 (排序)
- 分布式数据中心数据库和存储部署解决方案
- Java关键字final、static使用总结
- HDU 4540(威威猫系列故事——打地鼠)动态规划
- 相关使用教程汇总
- 二叉树差值最大(阿里2015)
- webview加载页面,JS方法不能加载的问题解决
- Smoke Testing(冒烟测试)(转)
- 【我的技术我做主】那些年从事过的.NET,追求的Java
- hdu 5402 Travelling Salesman Problem(构造+模拟)
- 在UIWebView中添加自定义编辑菜单 ,UIMenuController
- 几款Web富客户端(RIA)框架
- 洛谷1004 方格取数+洛谷1006 传纸条
- C#获取“所有用户”的路径, 我的桌面,我的文档,我的音乐,我的图片等等目录
- 多线程之临界区(Critical Section)
- 刚安装的win7系统如何提速
- struts2学习第一篇 环境配置 之 登录页面