2020 BIT冬训-C++STL F - CRB and String HDU - 5414
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.
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 aappleSample Output
No Yes Yes No
这题我w了好多次……虽然确实是一道单纯的水题。但有好多细节坑了我。例如题干中的105我误将其弄成了10000。
还有strlen函数之前就光秃秃的放在函数中,每次用到都需要调用一次strlen函数,导致tle。(创建两个整形变量存储即可)
以及题目的理解程度。由于apple能通过在l后面加个e使其变成applee。
所以只要保证t的第一个字符如果有重复的,s的第一个字符也必须拥有相同的重复即可。
下面是AC代码(之前那个一直没搞明白的TLE导致最后代码凌乱了许多)
#include<stdio.h> #include<cstring> using namespace std; char s[100005],ans[100005]; int t,len,flag; int main(){ scanf("%d",&t); while(t--){ scanf("%s%s",s,ans); len =0; flag =1; int n =strlen(s),m=strlen(ans); if(s[0]==ans[0]){ for(int i=1;i<m;i++) if(ans[i]==ans[0]){ if(n==m){ if(s[i]==ans[0]); else{ flag=0; break; } }else{ if(s[i]==ans[0]&&i<n); else if(i==n){ flag =0; break; }else if(i==n&&ans[i+1]!=ans[0]){ len==i; break; }else if(s[i]!=ans[0]){ flag =0; break; } } }else{ len = i; break; } if(flag ==1){ for(int i=len;i<m;i++) if(len == n){ break; }else if(s[len]==ans[i]) len++; if(len!=n) flag =0; } }else flag = 0; if(flag) printf("Yes\n"); else printf("No\n"); } return 0; }