wyh2000 and a string problem(HDU5284)
2016-01-22 17:33
337 查看
D - wyh2000 and a string problem
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 5284
Description
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 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 $\text{wyh}$ is a subsequence of some string or not, you just need to find a character $\text{w}$, a $\text{y}$, and
an $\text{h}$, so that the $\text{w}$ is in front of the $\text{y}$, and the $\text{y}$ is in front of the $\text{h}$.
One day a pupil holding a string asks him, "Is $\text{wyh}$ a subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character $\text{v}$s, then he would see it as one $\text{w}$. For example, the string $\text{vvv}$ will be seen as $\text{w}$, the string $\text{vvwvvv}$ will be seen as $\text{www}$,
and the string $\text{vwvv}$ will be seen as $\text{vww}$.
How would wyh2000 answer this question?
Input
The first line of the input contains an integer $T(T\le 10^5)$, denoting the number of testcases.
$N$ 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. Output $\text{Yes}$ if wyh2000 would consider $\text{wyh}$ as a subsequence of it, or $\text{No}$ otherwise.
Sample Input
4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh
Sample Output
No
Yes
Yes
No
题意:如果出现vv就被看成w,如果符合w在yde前面且y在h的前面,就输出Yes,否则输出No
#include<stdio.h>
#include<string.h>
int main()
{
char a[200000]; //这里要开大,要不然会超时,我之前开了100005,结果超时了
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
int w=0,y=0,h=0; //提前标记,很多题都是这样的
int l=strlen(a); //这里最好定义一个变量为字符串长度,如果下面情况多了有可能会超时,我之前做过一道这样的题
for(int i=0;i<l;i++)
{
if(w==0&&a[i]=='w')
{
w=1; //符合题意就把w变为1
continue; //这里结束本层循环,执行下一步
}
if(w==0&&i>=1&&a[i]=='v'&&a[i-1]=='v') //注意i>=1,因为要保证这个和前一个全部为v
{
w=1;
continue;
}
if(w==1&&y==0&&a[i]=='y') //在上一步成立的情况下走下一步
{
y=1;
continue;
}
if(w==1&&y==1&&h==0&&a[i]=='h') //上俩步都成立,走下一步
{
h=1;
break; //已经符合情况了,直接跳出循环
}
}
if(w==1&&y==1&&h==1) //三个条件都成立
printf("Yes\n");
else printf("No\n");
}
}
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 5284
Description
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 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 $\text{wyh}$ is a subsequence of some string or not, you just need to find a character $\text{w}$, a $\text{y}$, and
an $\text{h}$, so that the $\text{w}$ is in front of the $\text{y}$, and the $\text{y}$ is in front of the $\text{h}$.
One day a pupil holding a string asks him, "Is $\text{wyh}$ a subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character $\text{v}$s, then he would see it as one $\text{w}$. For example, the string $\text{vvv}$ will be seen as $\text{w}$, the string $\text{vvwvvv}$ will be seen as $\text{www}$,
and the string $\text{vwvv}$ will be seen as $\text{vww}$.
How would wyh2000 answer this question?
Input
The first line of the input contains an integer $T(T\le 10^5)$, denoting the number of testcases.
$N$ 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. Output $\text{Yes}$ if wyh2000 would consider $\text{wyh}$ as a subsequence of it, or $\text{No}$ otherwise.
Sample Input
4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh
Sample Output
No
Yes
Yes
No
题意:如果出现vv就被看成w,如果符合w在yde前面且y在h的前面,就输出Yes,否则输出No
#include<stdio.h>
#include<string.h>
int main()
{
char a[200000]; //这里要开大,要不然会超时,我之前开了100005,结果超时了
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
int w=0,y=0,h=0; //提前标记,很多题都是这样的
int l=strlen(a); //这里最好定义一个变量为字符串长度,如果下面情况多了有可能会超时,我之前做过一道这样的题
for(int i=0;i<l;i++)
{
if(w==0&&a[i]=='w')
{
w=1; //符合题意就把w变为1
continue; //这里结束本层循环,执行下一步
}
if(w==0&&i>=1&&a[i]=='v'&&a[i-1]=='v') //注意i>=1,因为要保证这个和前一个全部为v
{
w=1;
continue;
}
if(w==1&&y==0&&a[i]=='y') //在上一步成立的情况下走下一步
{
y=1;
continue;
}
if(w==1&&y==1&&h==0&&a[i]=='h') //上俩步都成立,走下一步
{
h=1;
break; //已经符合情况了,直接跳出循环
}
}
if(w==1&&y==1&&h==1) //三个条件都成立
printf("Yes\n");
else printf("No\n");
}
}
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- android string.xml文件中的整型和string型代替
- Android java 与 javascript互访(相互调用)的方法例子
- android上改变listView的选中颜色
- String.intern
- Varnish Install And Configure
- Prototype源码浅析 String部分(二)
- Ruby中的String对象学习笔记
- PostgreSQL ERROR: invalid escape string 解决办法
- 浅谈C++中的string 类型占几个字节
- 标准C++类string的Copy-On-Write技术
- C++实现string存取二进制数据的方法
- C#中string和StingBuilder内存中的区别实例分析
- PHP通过session id 实现session共享和登录验证的代码
- PHP STRING 陷阱原理说明
- c#中 String和string的区别介绍
- C#实现的图片、string相互转换类分享
- asp.net String.IsNullOrEmpty 方法
- JavaScript中字符串(string)转json的2种方法
- Insert Date and Time into Access