HDU 5284 wyh2000 and a string problem(字符串,水)

题意:比如给你一个串,要求判断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=4000000;

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=0;
        ans[++p]=s[0];
        for(int i=1; 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=1;
        bool w=false, y=false, h=false;
        while(i<len&&ans[i]!=‘w‘)   i++;//找3个字符出来
        if(i<len&&ans[i]==‘w‘)  w=1;

        while(i<len&&ans[i]!=‘y‘)   i++;
        if(i<len&&ans[i]==‘y‘)  y=1;

        while(i<len&&ans[i]!=‘h‘)   i++;
        if(i<len&&ans[i]==‘h‘)  h=1;
        if(w&&y&&h)    puts("Yes");
        else puts("No");
    }
    return 0;
}

AC代码

时间: 2024-12-17 10:48:32

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

HDU 5284 wyh2000 and a string problem(错误总结)

---恢复内容开始--- 题目链接:戳我(英文),戳我(中文) 题目大意: 看中文 样例解释: 略 解题思路: for循环跑一遍,遇到 vv 就变成 w 就行了 错误的代码 int k = 0, i; for(i = 0; str[i+1]; i++) { printf("%d %c\n", i, str[i]); if(str[i] == 'v' && str[i+1] == 'v') { i = i + 1; //这里不能加1 str[i] = 'w'; //k++

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

代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",s); int w=0,y=0,h=0; int len=strlen(s); for(int i=0; i<len; i++) { if(w==0&&

[Water]Hdu 5284 wyh2000 and a string problem

#include <cstdio> #include <cstring> using namespace std; const int MAXN=10000000+5; char a[MAXN]; int t; char b[3]={'w','y','h'}; int main() { scanf("%d",&t); getchar(); while(t--){ gets(a); for(int i=0;a[i+1];++i)if(a[i]=='v'&a

bestcoder 47# wyh2000 and a string problem (水题)

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 484    Accepted Submission(s): 232 Problem Description Young theoretical computer scientist wyh2000 is teaching you

HDU5284——水,strlen坑——wyh2000 and a string problem

Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings. A subsequence of a string s is a string that can be derived from s by deleting some characters without changing the order of the remaining charac

HDU 5328(2015多校4)-Problem Killer(水题)

题目地址:HDU 5328 题意:在一个长度为n的序列中取出连续的k个数,让这k个数组成等差数列或者等比数列,问这样的k最大可以是多少. Ps:注意用double搞,因为等比数列求公比相除可能为小数. #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #i

HDU 5284

wyh2000 and a string problem http://acm.hdu.edu.cn/showproblem.php?pid=5284 Accepts: 428 Submissions: 1313 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) 问题描述 青年理论计算机科学家wyh2000在教小学生一些基础的字符串概念. 定义一个字符串s的子序列为将s中一些元素删掉

HDU-5284-wyh2000 and a string problem(BestCoder Round #48 ($))

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 492    Accepted Submission(s): 239 Problem Description Young theoretical computer scientist wyh2000 is teaching you

hdu 5008(2014 ACM/ICPC Asia Regional Xi&#39;an Online ) Boring String Problem(后缀数组&amp;二分)

Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 219    Accepted Submission(s): 45 Problem Description In this problem, you are given a string s and q queries. For each que