wyh2000 and a string problem(模拟)
2015-07-18 21:48
393 查看
Link:http://acm.hdu.edu.cn/showproblem.php?pid=5284
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 177 Accepted Submission(s): 91
Problem 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 wyh is
a subsequence of some string or not, you just need to find a character w,
a y,
and an h,
so that the w is
in front of the y,
and the y is
in front of the h.
One day a pupil holding a string asks him, "Is wyh a
subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character vs,
then he would see it as one w.
For example, the string vvv will
be seen as w,
the string vvwvvv will
be seen as www,
and the string vwvv will
be seen as vww.
How would wyh2000 answer this question?
Input
The first line of the input contains an integer T(T≤105),
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 Yes if
wyh2000 would consider wyh as
a subsequence of it, or No otherwise.
Sample Input
Sample Output
Source
BestCoder Round #48 ($)
AC code:
wyh2000 and a string problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 177 Accepted Submission(s): 91
Problem 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 wyh is
a subsequence of some string or not, you just need to find a character w,
a y,
and an h,
so that the w is
in front of the y,
and the y is
in front of the h.
One day a pupil holding a string asks him, "Is wyh a
subsequence of this string?"
However, wyh2000 has severe myopia. If there are two or more consecutive character vs,
then he would see it as one w.
For example, the string vvv will
be seen as w,
the string vvwvvv will
be seen as www,
and the string vwvv will
be seen as vww.
How would wyh2000 answer this question?
Input
The first line of the input contains an integer T(T≤105),
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 Yes if
wyh2000 would consider wyh as
a subsequence of it, or No otherwise.
Sample Input
4 woshiyangli woyeshiyangli vvuuyeh vuvuyeh
Sample Output
No Yes Yes No
Source
BestCoder Round #48 ($)
AC code:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; char s[3145730]; int T,l,i,fg1,fg2,fg3; int main(){ scanf("%d",&T); getchar(); while(T--){ gets(s); l=strlen(s); fg1=fg2=fg3=0; for(i=1;i<l;i++){ if(s[i-1]=='w'||(s[i]=='v'&&s[i-1]=='v')) fg1=1; if(fg1&&s[i]=='y') fg2=1; if(fg2&&s[i]=='h'){ fg3=1; break; } } if(fg3) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- Linux通配符
- Block的copy时机
- JVM系列五:垃圾回收器
- 浅谈java main()
- POJ 2350 Above Average
- Html 5知识总结
- AFNetworking 的导入(一)
- DirectX11 创建输入布局
- CSS布局
- codeforces gym 100187M Heaviside Function
- 解决 Firefox 火狐浏览器下载 .exe 文件卡住的问题 以及关闭测试版cache2
- AYIT暑假集训大二第一周周六赛 B - 汉字统计
- 02-数组与集合之间的互相转换
- 排序算法之归并排序
- ZOJ 1940 Dungeon Master
- 【C语言】使用递归的整数输出(高位到低位)/输出一个菱形(能够确定行数)
- boost之variant使用
- JavaScript匿名函数与闭包
- Myeclipse验证js语法报错
- 广义线性回归拟合教程和源码