Codeforces Round 1017 (Div. 4) D. Tung Tung Sahur
作者:
fate222
,
2025-04-25 16:31:11
· 江苏
,
所有人可见
,
阅读 2
Codeforces Round 1017 (Div. 4) D. Tung Tung Sahur
原题链接
#include <bits/stdc++.h>
using namespace std;
int t, n;
int cal(string& str, int x)
{
char c = str[x];
int cnt = 1;
for(int i = x + 1;str[i];i++)
{
if(str[i] != c) break;
else
{
cnt++;
str[i] = 'A';
}
}
return cnt;
}
bool solve()
{
string s, p;
vector<int> a, b;
cin >> p >> s;
for(int i = 0;p[i];i++)
{
if(p[i] == 'R') a.push_back(cal(p, i));
else if(p[i] == 'L') a.push_back(-cal(p, i));
}
for(int i = 0;s[i];i++)
{
if(s[i] == 'R') b.push_back(cal(s, i));
else if(s[i] == 'L') b.push_back(-cal(s, i));
}
if(a.size() != b.size()) return false;
for(int i = 0;i < a.size();i++)
{
if(a[i] > 0 && b[i] < 0) return false;
if(a[i] < 0 && b[i] > 0) return false;
a[i] = abs(a[i]);
b[i] = abs(b[i]);
if(b[i] < a[i] || b[i] > 2 * a[i]) return false;
}
return true;
}
int main()
{
cin >> t;
while(t--)
{
if(solve()) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}