hdu 5311 Hidden String(find,substr)
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string s of length n. He wants to find three nonoverlapping substrings s[l1..r1], s[l2..r2], s[l3..r3] that:1. 1≤l1≤r1<l2≤r2<l3≤r3≤n2. The concatenation of s[l1..r1], s[l2..r2], s[l3..r3] is "anniversary".
There are multiple test cases. The first line of input contains an integer T (1≤T≤100), indicating the number of test cases. For each test case:There's a line containing a string s (1≤|s|≤100) consisting of lowercase English letters.
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
2 annivddfdersewwefary nniversarya
YES NO
题意:从s串中找出3段连续的字串组成“anniversary”
复习了下find,substr的用法,老是忘记
s.substr(i,j)表示从s串的i位置开始,长度为j的子串。
s.find(p,i),p为字串,表示从s串的i位置开始,寻找有没有等于p的子串,如果有返回s的首地址,否则返回-1
这题枚举“anniversary”的3个子串,在给出的s串中寻找就可以了!
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<queue> 6 #include<cmath> 7 #include<stdlib.h> 8 #include<map> 9 using namespace std; 10 string s; 11 string goal="anniversary"; 12 bool solve(){ 13 for(int i=1;i<=9;i++){ 14 int ans1=s.find(goal.substr(0,i),0); 15 if(ans1<0) continue; 16 for(int j=1;j+i<=10;j++){ 17 int ans2=s.find(goal.substr(i,j),ans1+i); 18 if(ans2<0) continue; 19 int k=11-i-j; 20 int ans3=s.find(goal.substr(i+j,k),ans2+j); 21 if(ans3<0) continue; 22 return true; 23 } 24 } 25 return false; 26 } 27 int main() 28 { 29 int t; 30 scanf("%d",&t); 31 while(t--){ 32 cin>>s; 33 if(solve()){ 34 printf("YES\n"); 35 } 36 else{ 37 printf("NO\n"); 38 } 39 } 40 return 0; 41 }
View Code
转载于:https://www.cnblogs.com/UniqueColor/p/4799024.html
hdu 5311 Hidden String(find,substr)相关推荐
- 【HDU - 4055】Number String(dp,思维)
题干: The signature of a permutation is a string that is computed as follows: for each pair of consecu ...
- 【HDU - 5012】Dice(模拟,bfs)
题干: There are 2 special dices on the table. On each face of the dice, a distinct number was written. ...
- 【CodeForces - 1084C】The Fair Nut and String(思维,组合数学)
题干: The Fair Nut found a string ss. The string consists of lowercase Latin letters. The Nut is a cur ...
- 【HDU - 1220】Cube (组合数学,简单)
题干: Cowl is good at solving math problems. One day a friend asked him such a question: You are given ...
- hdu 4915 Parenthese sequence(贪心,模拟)
题目: Parenthese sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Jav ...
- HDU Problem - 1969 Pie(二分,精度)
题目链接 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pi ...
- HDU Problem - 6396 Swordsman(优先队列,模拟)
题目链接 Problem Description Lawson is a magic swordsman with kkk kinds of magic attributes v1,v2,v3,-,v ...
- JavaScript中String的slice(),substr(),substring()三者区别
JavaScript中String的slice(),substr(),substring()三者区别 共同之处 从给定的字符串中截取片段,并返回全新的这片段的字符串对象,且不会改动原字符串. 具体不同 ...
- HDU - 1495 非常可乐(BFS,数学)
HDU - 1495 非常可乐(BFS,数学) 巨佬的数学解法 #include<iostream> using namespace std; int gcd(int a,int b) { ...
最新文章
- Servlet--02--xml文件配置
- 如何安装Pycharm官方统计代码行插件
- 第三讲 一阶线性ODE
- Ubuntu系统如何安装软件
- vue循环如何传参数 php,vue循环列表动态数据的处理方法(代码)
- Dubbo(七)之自动加载环境变量
- Lineageos14 20180525更新
- C++中doulbe/float/int转为CString方法(转)
- wxWidgets第四课 EVT_LEFT_UP关联鼠标弹起事件不生效
- linux脚本使用scp自动传输,使用Shell脚本自动传输SCP文件
- Angular 2 之七 依赖注入
- java WebSocket的实现以及Spring WebSocket
- mysql 升序_MySQL之排序检索数据
- 【白话模型量化系列一】矩阵乘法量化
- 计算机上的证书安装不了,数字证书认不到怎么办?
- 金彩教育:拼多多运营的方法有哪些
- 初学C语言——三位数倒序
- vue实现在canvas画布上实现绘制涂抹功能
- 十年磨一剑,剑出荡魑魅
- 一个模拟斗地主的小程序
热门文章
- Python列表综合
- win7的vmware中安装ubuntu 13.04看不到共享目录
- 树莓派 st-link master使用ST-LINK V2下载STM32程序 支持F0 F1 F2 等
- 04 | 基础篇:经常说的 CPU 上下文切换是什么意思?(下)
- MySQL(8)数据库中的高级(进阶)正则和存储过程
- python三大流程控制
- 使用率激增250%,这份报告再次将 Serverless 推向幕前
- 如何实现32.5万笔/秒的交易峰值?阿里交易系统TMF2.0技术揭秘
- MySQL复习资料(二)——MySQL-DDL语句
- 【实施工程师之家】linux安装tomcat(yum安装tomcat)