CRB and String (字符串思维题)
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”.
当s为 t 的子序列 ,并且 s 从第一位开始相同的字母的个数要大于等于 t ,则输出Yes,否则No。
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin>>T;while(T--){string s,t;cin>>s>>t;int k=0,l=0,r=0;for(int i=0;i<t.size();i++)if(k<s.size()&&s[k]==t[i]) k++;while(s[l]==s[l+1]&&l<s.size()-1) l++;while(t[r]==t[r+1]&&r<t.size()-1) r++;if(k==s.size()&&s[0]==t[0]&&l>=r) cout<<"Yesn";else cout<<"Non";}return 0;
}
本文发布于:2024-01-30 18:13:46,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170660963021891.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |