hdu 5414 CRB and String(贪心)
2015-08-21 22:36
357 查看
题目链接:hdu 5414 CRB and String
减掉两串开头部分相同的地方,并且如果开头部分不一样或者是t串的要比s串的长即为不可行(s=aabb,t=aaabb),后面部分分情况匹配,最后s串有剩即为不可行。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn], t[maxn];
bool judge () {
int ms = 1;
while (s[ms-1] == s[ms]) ms++;
int mt = 1;
while (t[mt-1] == t[mt]) mt++;
if (s[0] != t[0] || ms < mt) return false;
int m = strlen(t), p = mt, bo = false;
//char pre = s[ms-1];
for (int i = mt; i < m; i++) {
if (s[p] == t[i]) {
// pre = s[ms];
p++, bo = false;
} else if (bo || t[i] != t[i-1]) {
//pre = t[i];
bo = true;
} else {
bo = false;
}
}
//printf("!%c!\n", s[p]);
return s[p] == '\0';
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%s%s", s, t);
printf("%s\n", judge() ? "Yes" : "No");
}
return 0;
}
减掉两串开头部分相同的地方,并且如果开头部分不一样或者是t串的要比s串的长即为不可行(s=aabb,t=aaabb),后面部分分情况匹配,最后s串有剩即为不可行。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn], t[maxn];
bool judge () {
int ms = 1;
while (s[ms-1] == s[ms]) ms++;
int mt = 1;
while (t[mt-1] == t[mt]) mt++;
if (s[0] != t[0] || ms < mt) return false;
int m = strlen(t), p = mt, bo = false;
//char pre = s[ms-1];
for (int i = mt; i < m; i++) {
if (s[p] == t[i]) {
// pre = s[ms];
p++, bo = false;
} else if (bo || t[i] != t[i-1]) {
//pre = t[i];
bo = true;
} else {
bo = false;
}
}
//printf("!%c!\n", s[p]);
return s[p] == '\0';
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%s%s", s, t);
printf("%s\n", judge() ? "Yes" : "No");
}
return 0;
}
相关文章推荐
- 对于Netty的十一个疑问
- C# 泛型类的实现,链表的封装LinkedListNode
- 架构必备:Rate limiting 的作用和常见方式 - 互联网技术和架构
- [题解+总结]20150821
- CentOS7.0下,apache不能正常运行的解决思路
- excel导入导出优化
- 联发科笔试
- iOS逆向工程-动态分析
- hibernate *.hbm.xml 与 hibernate.cfg.xml基本模板(mysql)
- 春有它的记忆,秋有它的情怀
- artTemplate的嵌套使用
- Hibernate 一对多控制总结
- Hibernate 一对多关系双向控制(多控制一)
- iOS逆向工程-静态分析
- memcache实例:缓存一条sql语句的执行结果
- Mac在zsh环境安装Maven
- Opencv输出图像函数-imwrite
- With one file handling all requests, you can centralize things such as security handling, configurat
- js的DOM(节点操作)
- udp 双机通信(服务器循环检测)2