hdu 5311 Hidden String(水)
2015-08-05 22:08
239 查看
题目链接:hdu 5311 Hidden String
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105;
//const int N = 11;
const char S[maxn] = "anniversary";
bool dfs (char* t, int l, int r, int d) {
if (d >= 3)
return false;
for (; t[l]; l++) {
int v = 0;
while (t[l+v] && S[r+v] && t[l+v] == S[r+v])
v++;
if (S[r+v] == '\0')
return true;
if (dfs(t, l+v, r+v, d+1))
return true;
}
return false;
}
int main () {
int cas;
char s[maxn];
scanf("%d", &cas);
while (cas--) {
scanf("%s", s);
printf("%s\n", dfs(s, 0, 0, 0) ? "YES" : "NO");
}
return 0;
}
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 105;
//const int N = 11;
const char S[maxn] = "anniversary";
bool dfs (char* t, int l, int r, int d) {
if (d >= 3)
return false;
for (; t[l]; l++) {
int v = 0;
while (t[l+v] && S[r+v] && t[l+v] == S[r+v])
v++;
if (S[r+v] == '\0')
return true;
if (dfs(t, l+v, r+v, d+1))
return true;
}
return false;
}
int main () {
int cas;
char s[maxn];
scanf("%d", &cas);
while (cas--) {
scanf("%s", s);
printf("%s\n", dfs(s, 0, 0, 0) ? "YES" : "NO");
}
return 0;
}
相关文章推荐
- iOS在照片上添加水印
- YUV格式学习:YUYV、YVYU、UYVY、VYUY格式转换成RGB24
- 正则匹配
- 【asp】Jmail组件发邮件
- machine learning in coding(python):使用xgboost构建预测模型
- STL容器之优先队列
- Android Data Binding语法解析(二)
- linux命令——tar
- Android Data Binding语法解析(二)
- POJ3070——矩阵快速幂——Fibonacci
- 黑马程序员——java学习10(毕17)——工具类
- cocos2d-x学习笔记(一)C++基础知识
- 人机交互,十进制和二进制的对话,捎带认清八进制(女友)和十六进制(我)的本质。
- ubuntu install wiznote
- 8.5总结
- AJAX快速掌握
- Python 之 Python与MATLAB 作图小结
- 希尔排序
- Windows command中的Git代理设置
- Oracle学习之DATAGUARD(八) Switchover与failover