2015 多校联赛 ——HDU5414()
2015-08-31 03:15
309 查看
Problem Description
CRB has two strings s and t.
In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.
CRB wants to convert s to t.
But is it possible?
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.
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
Sample Input
Sample Output
题意:
每组测试数据输入两个字符串a和b,你可以选择字符串a中的任意一个字母x,在这个字母的后面加任意一个不是x的字母.
思路:
如果a比b长,不考虑
1. a 的序列是否能在 b中找到
2. a中前x个字母相同,b中前y个字母相同, x >=y
aaab - > aabab 或者 aaab->aaabb
CRB has two strings s and t.
In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.
CRB wants to convert s to t.
But is it possible?
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.
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
Sample Input
4 a b cat cats do do apple aapple
Sample Output
No Yes Yes No
题意:
每组测试数据输入两个字符串a和b,你可以选择字符串a中的任意一个字母x,在这个字母的后面加任意一个不是x的字母.
思路:
如果a比b长,不考虑
1. a 的序列是否能在 b中找到
2. a中前x个字母相同,b中前y个字母相同, x >=y
aaab - > aabab 或者 aaab->aaabb
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<string> #include<algorithm> using namespace std; #define maxn 200050 char stra[100005]; char strb[100005]; int main() { int T; scanf("%d",&T); while(T--) { int len1= 0,len2 = 0; scanf("%s%s",stra,strb); len1 = strlen(stra); len2 = strlen(strb); if(len1 > len2) printf("No\n"); else { int flag = 1,i = 0,j = 0; for(; j<len2&&i<len1; j++) //a是否是b的子串 if(strb[j]==stra[i]) i++; if(i<len1) flag = 0; i=0,j=0; while(i<len1&&stra[i]==stra[0]) //aaab前面连续相同字母不可能变多 i++; while(j<len2&&strb[j]==strb[0]) j++; if(i >= j && flag && stra[0] == strb[0]) printf("Yes\n"); else printf("No\n"); } } return 0; }
相关文章推荐
- 【C语言】指针
- C#泛型
- How to properly logout of a Java EE 6 Web Application after logging in
- hdu5423
- hdu5422
- *Binary Tree Paths
- Session or cookie confusion
- hdu1242
- 情感系
- debian的iceweasel安装flash插件
- php正则表达式的基本语法
- 常用代码段(二)冒泡排序算法Java实现
- 时间管理领域的三八原则
- seajs部分版本iPhone测试卡死
- 有种激情,当你休息的时候来敲门。
- 太极拳技击秘诀·松腰开跨的重要性
- HTTP网络协议(三)
- C#的事件
- iOS-按钮(UIButton)不能和用户交互的五种情况
- Invert Binary Tree