日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 5311 Hidden String(find,substr)

發(fā)布時(shí)間:2024/8/26 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 5311 Hidden String(find,substr) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Problem Description 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".

?

?

Input 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.

?

?

Output For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

?

?

Sample Input 2 annivddfdersewwefary nniversarya

?

?

Sample Output YES NO

?

?

Source BestCoder 1st Anniversary ($)

?題意:從s串中找出3段連續(xù)的字串組成“anniversary”

?

復(fù)習(xí)了下find,substr的用法,老是忘記

s.substr(i,j)表示從s串的i位置開始,長度為j的子串。

s.find(p,i),p為字串,表示從s串的i位置開始,尋找有沒有等于p的子串,如果有返回s的首地址,否則返回-1

?

這題枚舉“anniversary”的3個(gè)子串,在給出的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

?

轉(zhuǎn)載于:https://www.cnblogs.com/UniqueColor/p/4799024.html

總結(jié)

以上是生活随笔為你收集整理的hdu 5311 Hidden String(find,substr)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。