HDU - 5284 wyh2000 and a string problem

来源:互联网 发布:淘宝上的蜜蜡是真的吗 编辑:程序博客网 时间:2024/05/14 07:01
Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings.

A subsequence of a string
ss is a string that can be derived from ss by deleting some characters without changing the order of the remaining characters. You can delete all the characters or none, or only some of the characters.

He also teaches the pupils how to determine if a string is a subsequence of another string. For example, when you are asked to judge whether
wyhwyh is a subsequence of some string or not, you just need to find a character ww, a yy, and an hh, so that the ww is in front of the yy, and the yy is in front of the hh.

One day a pupil holding a string asks him, "Is
wyhwyh a subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character
vvs, then he would see it as one ww. For example, the string vvvvvv will be seen as ww, the string vvwvvvvvwvvv will be seen as wwwwww, and the string vwvvvwvv will be seen as vwwvww.

How would wyh2000 answer this question?
Input
The first line of the input contains an integer T(T105)T(T105), denoting the number of testcases.

NN lines follow, each line contains a string.

Total string length will not exceed 3145728. Strings contain only lowercase letters.

The length of hack input must be no more than 100000.
Output
For each string, you should output one line containing one word. OutputYesYes if wyh2000 would consider wyhwyh as a subsequence of it, or NoNo otherwise.
Sample Input
4woshiyangliwoyeshiyanglivvuuyehvuvuyeh
Sample Output
NoYesYesNo

水题 理解题意 按描述处理字符串....
AC代码:

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>char s[4000005];int main(){    int t,temp[5],i,n;    scanf("%d",&t);    getchar();    while(t--)    {        gets(s);        n=strlen(s);        memset(temp,0,sizeof(temp));        for(i=0;i<n;i++)        {            if(s[i]=='w'||(s[i]=='v'&&s[i+1]=='v'))            {                temp[1]++;            }            else if(s[i]=='y'&&temp[1]!=0)            {                temp[2]++;            }            else if(s[i]=='h'&&temp[1]!=0&&temp[2]!=0)            {                temp[3]++;            }            if(temp[1]!=0&&temp[2]!=0&&temp[3]!=0)            {                printf("Yes\n");                break;            }        }        if(temp[1]==0||temp[2]==0||temp[3]==0)        {            printf("No\n");        }    }    return 0;}




























0 0
原创粉丝点击