HDU 5284 wyh2000 and a string problem(查找字符)
来源:互联网 发布:李炎恢php第四季下载 编辑:程序博客网 时间:2024/04/29 01:14
wyh2000 and a string problem
Accepts: 428
Submissions: 1313
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 131072/65536 K (Java/Others)
问题描述
青年理论计算机科学家wyh2000在教小学生一些基础的字符串概念。定义一个字符串s 的子序列为将s 中一些元素删掉得到的字符串。可以删掉全部元素,可以不删,也可以只删一些。他还教了小学生如何判断一个串是不是另一个串的子序列。比如给你一个串,要求判断wyh 是不是它的子序列,那么你只需要找一个w ,找一个y ,再找一个h ,使得w 在y 前面,y 在h 前面即可。有一天小学生拿着一个串问他“wyh 是不是这个串的子序列?”但是wyh2000有重度近视眼,如果字符串中有一段连续的v (至少两个),那么他会把它看成一个w 。例如,字符串vvv 会被看成w ,字符串vvwvvv 会被看成www ,字符串vwvv 会被看成vww 。请问wyh2000会怎么回答这个问题?
输入描述
第一行为数据组数T(1≤T≤105) 。接下来T 行,每行一个字符串,表示小学生拿来问wyh2000的串。总串长不超过3145728。只包含小写字母。hack数据字符串长度不超过100000。
输出描述
对于每组数据,如果wyh2000会把wyh 看成该串的子串,那么输出一行Yes ,否则输出一行No 。
输入样例
4woshiyangliwoyeshiyanglivvuuyehvuvuyeh
输出样例
NoYesYesNo
解题思路:题目简单的说就是问能否在一个字符串中依次找到‘w’,‘y’,‘h’或“vv”,‘y’,‘h’?既然是依次找到,那么我们就可以得知,如果‘w’或“vv”没有找到,那么就没必要找‘y’;同样的,如果‘w’和‘y'或“vv”和’y'没有找到,就没必要找‘h’。想明白这一点,就可以定义一个变量flag1用来标记‘w’或“vv”有没有找到,定义另一个变量flag2用来标记‘y’有没有找到,再定义一个变量flag3用来标记‘h’有没有找到。
代码如下:
#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <string>#include <vector>#include <deque>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <numeric>#include <iomanip>#include <bitset>#include <sstream>#include <fstream>#include <limits.h>#define debug "output for debug\n"#define pi (acos(-1.0))#define eps (1e-4)#define inf (1<<28)#define sqr(x) (x) * (x)using namespace std;typedef long long ll;typedef unsigned long long ULL;int main(){ string s; int i,j,t; scanf("%d",&t); while(t--) { cin>>s; int flag1=0,flag2=0,flag3=0; for(i=0;i<s.size();i++) { if(s[i]=='w') flag1=1; if(s[i]=='v'&&s[i+1]=='v') flag1=1; if(s[i]=='y'&&flag1==1) flag2=1; if(s[i]=='h'&&flag2==1) flag3=1; } if(flag3) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- HDU 5284 wyh2000 and a string problem(查找字符)
- HDU 5284 wyh2000 and a string problem
- hdu 5284 wyh2000 and a string problem
- HDU - 5284 wyh2000 and a string problem
- HDU-5284-wyh2000 and a string problem(BestCoder Round #48 ($))
- wyh2000 and a string problem(模拟)
- wyh2000 and a string problem(HDU5284)
- hdu 5284 wyh2000 and a string problem(没有算法,只考思维,字符数组得开20万,不然太小了)
- HDU 5284 wyh2000 and a string problem——BestCoder Round #48(普通的字符串处理)
- wyh2000 and a string problem(bc题)
- BestCoder Round #48 ($) wyh2000 and a string problem
- bestcoder 48# wyh2000 and a string problem (水题)
- BestCoder Round #48 ($)HDU5284 wyh2000 and a string problem
- hdu 5285 wyh2000 and pupil
- HDU 5285 wyh2000 and pupil
- HDU 5285 wyh2000 and pupil
- HDU 5285:wyh2000 and pupil
- hdu 5285 wyh2000 and pupil
- JavaWeb学习总结(基于Servlet+JSP+JavaBean开发模式的用户登录注册)
- pthread_attr_init 线程属性
- (Windows Maven项目)Jedis数据库的安装和操作实现
- 学习meteor之后的总结
- JSP乱码
- HDU 5284 wyh2000 and a string problem(查找字符)
- 子数组最大乘积
- CORS(跨域资源共享)简介。。。
- uva122_二叉树的层次历遍
- HTML5多媒体素材的应用
- anroid studio快捷键
- OC类 之 NSString
- [基本实验] 探测Web目录结构和隐藏的敏感文件
- OC的字符串