hdu 5414 CRB and String(字符串模拟)
来源:互联网 发布:游光网络拉勾网 编辑:程序博客网 时间:2024/05/21 06:43
CRB and String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1787 Accepted Submission(s): 579
Problem Description
CRB has two strings s and t .
In each step, CRB can select arbitrary characterc of s and insert any character d (d ≠ c ) just after it.
CRB wants to converts to t . But is it possible?
In each step, CRB can select arbitrary character
CRB wants to convert
Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case there are two strings s and t , one per line.
1 ≤T ≤ 105
1 ≤|s| ≤ |t| ≤ 105
All strings consist only of lowercase English letters.
The size of each input file will be less than 5MB.
1 ≤
1 ≤
All strings consist only of lowercase English letters.
The size of each input file will be less than 5MB.
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
Sample Input
4abcatcatsdodoappleaapple
Sample Output
NoYesYesNo
思路:直接模拟便是。 注意abc和abbbbbbbbbbc是合法的,因为可以在a后面多次插入b
代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;#define N 100005char s[N],t[N];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%s %s",s,t); int lens=strlen(s),lent=strlen(t),nt=1; int flag=0; if(s[0]!=t[0]) flag=1; else { for(int i=1; i<lens; ) { if(s[i]==t[nt]) { i++; nt++; continue; } int now=nt-1; while(t[now]==t[nt]) now--; if(now==-1) { flag=1; break; } nt++; if(nt>=lent) { flag=1; break; } } for(int i=nt; i<lent; i++) { if(t[i]==t[i-1]) { int now=nt-1; while(t[now]==t[nt]) now--; if(now==-1) { flag=1; break; } } } } if(flag) printf("No\n"); else printf("Yes\n"); } return 0;}
0 0
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- 贪心,模拟,构造(HDU 5414,CRB and String)
- HDU5414 CRB and String 字符串+模拟+思维
- HDU 5414 CRB and String
- hdu 5414 CRB and String
- HDU 5414 CRB and string
- hdu 5414 CRB and String
- HDU 5414CRB and String
- HDU 5414(2015多校10)-CRB and String(字符串处理)
- HDOJ 5414 CRB and String 模拟
- hdu 5414 CRB and String (贪心)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String(贪心)
- hdu 5414 CRB and String(贪心)
- [思路题] hdu 5414 CRB and String
- HDU 5414 CRB and String(水~)
- 模拟 hdu5414 CRB and String
- iOS: SegmentControl 实现页面切换的四种方法
- Facade(外观模式)
- 梳理js-工作原理
- linux内核升级
- 梳理css-运行原理
- hdu 5414 CRB and String(字符串模拟)
- 企业管理授权指南(一)-前言
- 122. Best Time to Buy and Sell Stock II
- Android 面试题
- 中国梦社交平台立项建议书
- 2016 alictf Timer android writeup
- RecyclerView setHasFixedSize(true); 的作用
- Libxml2在linux下的使用
- apk重打包和签名(jarsigner)