题意:比如给你一个串,要求判断wyh是不是它的子序列,那么你只需要找一个w,找一个y,再找一个h,使得w在y前面,y在h前面即可。有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”.但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w。例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww。请问wyh2000会怎么回答这个问题?输出yes和no。

思路:其实就是将两个以上的v换成w,再来看是否能有'wyh'子串的存在。可以写更技巧些,但是为了快,就随便写了。还好过了。

//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=; char s[N];
char ans[N]; int main()
{
//freopen("input.txt", "r", stdin);
int t;
cin>>t;
while(t--)
{
scanf("%s",s);
int len=strlen(s);
int p=;
ans[++p]=s[];
for(int i=; i<len; i++)//替换掉
{
if(ans[p]=='v'&&s[i]=='v')
{
ans[p]='w';
while(s[i]=='v') i++;
i--;
}
else ans[++p]=s[i];
}
ans[++p]='\0';
len=p; int i=;
bool w=false, y=false, h=false;
while(i<len&&ans[i]!='w') i++;//找3个字符出来
if(i<len&&ans[i]=='w') w=; while(i<len&&ans[i]!='y') i++;
if(i<len&&ans[i]=='y') y=; while(i<len&&ans[i]!='h') i++;
if(i<len&&ans[i]=='h') h=;
if(w&&y&&h) puts("Yes");
else puts("No");
}
return ;
}

AC代码

HDU 5284 wyh2000 and a string problem(字符串,水)的更多相关文章

  1. hdu 5284 wyh2000 and a string problem(没有算法,仅仅考思维,字符数组得开20万,不然太小了)

    代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { ...

  2. bestcoder 48# wyh2000 and a string problem (水题)

    wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K ...

  3. hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)

    Problem - 3374   KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html   循环节推导的证明相当 ...

  4. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  5. hdu 5772 String problem 最大权闭合子图

    String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...

  6. hdu String Problem(最小表示法入门题)

    hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include &l ...

  7. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. String Problem hdu 3374 最小表示法加KMP的next数组

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. ACM: HDU 5285 wyh2000 and pupil-二分图判定

     HDU 5285  wyh2000 and pupil Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

随机推荐

  1. Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp

    题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...

  2. 剑指offer--面试题13

    题目:以O(1)的时间复杂度删除单链表中的某个节点 自己所写代码如下: //以O(1)时间删除链表节点 //要求:单向链表,头指针,待删节点指针 //链表节点 struct ListNode { in ...

  3. 【转载】CCombobox使用大全

    一.如何添加/删除Combo Box内容 1. 在Combo Box控件属性的Data标签里面添加,一行表示Combo Box下拉列表中的一行.换行用ctrl+回车. 2. 在程序初始化时动态添加 如 ...

  4. 增强学习(Reinforcement Learning and Control)

    增强学习(Reinforcement Learning and Control)  [pdf版本]增强学习.pdf 在之前的讨论中,我们总是给定一个样本x,然后给或者不给label y.之后对样本进行 ...

  5. 使用静态变量的方法求n!

    下面的程序可以输出1-5的阶乘值,如果需要把5改为n,则可求出1-n的阶乘值. void main() { setvbuf(stdout,NULL,_IONBF,); int fac(int n); ...

  6. Memcache安全配置

    Memcache安全配置 瞌睡龙 · 2014/01/20 17:59 0x00 Memcache简介 Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash ...

  7. Browser detect

    A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give s ...

  8. Embedding Lua in C: Using Lua from inside C.

    Requirments:     1: The Lua Sources.    2: A C compiler - cc/gcc/g++ for Unix, and Visual C++ for Wi ...

  9. SPOJ LCS2 后缀自动机

    多串的LCS,注意要利用拓扑序更新suf的len. 我用min,max,三目会超时,所以都改成了if,else #pragma warning(disable:4996) #include<cs ...

  10. /bin/bash^M: bad interpreter: No such file or dire

    在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识.  查看脚本文件是dos格式还是unix格式的几种办 ...