wyh2000 and a string problemTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 484Accepted Submission(s): 232
Problem Description
Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings.A subsequence of a stringis a string that can be derived fromby 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 whetheris a subsequence of some string or not, you just need to find a character, a, and an, so that theis in front of the, and theis in front of the.One day a pupil holding a string asks him, "Isa subsequence of this string?"However, wyh2000 has severe myopia. If there are two or more consecutive characters, then he would see it as one. For example, the stringwill be seen as, the stringwill be seen as, and the stringwill be seen as.How would wyh2000 answer this question?
Input
The first line of the input contains an integer, denoting the number of testcases.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. Outputif wyh2000 would consideras a subsequence of it, orotherwise.
Sample Input
4woshiyangliwoyeshiyanglivvuuyehvuvuyeh
Sample Output
NoYesYesNo
Source
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char s[40000000];char str[5]={"wyh"};int main(){int t;scanf("%d",&t);while(t–){scanf("%s",s);int len = strlen(s);int id=0;for(int i = 0;i < len;i++){if(id==3) break;if(s[i]==str[id]) id++;if(id==0 && s[i]=='v' && s[i+1]=='v') id++;}//printf("%d\n",id);if(id==3) printf("Yes\n");else printf("No\n");}}
版权声明:本文为博主原创文章,未经博主允许不得转载。
,那风再温柔。太深的流连便成了一种羁绊,