山师第二场训练赛

G - 【The__Flash】的水题

You are given two strings of equal length ss and tt consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.
During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.
For example, if ss is “acbc” you can get the following strings in one operation:

  • “aabc” (if you perform s2=s1s2=s1);
  • “ccbc” (if you perform s1=s2s1=s2);
  • “accc” (if you perform s3=s2s3=s2 or s3=s4s3=s4);
  • “abbc” (if you perform s2=s3s2=s3);
  • “acbb” (if you perform s4=s3s4=s3);

Note that you can also apply this operation to the string t.
Please determine whether it is possible to transform ss into tt, applying the operation above any number of times.
Note that you have to answer q independent queries.
Input
The first line contains one integer q(1≤q≤100) — the number of queries. Each query is represented by two consecutive lines.
The first line of each query contains the string s (1≤|s|≤100) consisting of lowercase Latin letters.
The second line of each query contains the string t (1≤|t|≤100, |t|=|s|) consisting of lowercase Latin letters.
Output
For each query, print “YES” if it is possible to make ss equal to tt, and “NO” otherwise.
You may print every letter in any case you want (so, for example, the strings “yEs”, “yes”, “Yes”, and “YES” will all be recognized as positive answer).
Example
Input

3
xabb
aabx
technocup
technocup
a
z
Output
YES
YES
NO
Note
In the first query, you can perform two operations s1=s2 (after it s turns into “aabb”) and t4=t3 (after it t turns into “aabb”).
In the second query, the strings are equal initially, so the answer is “YES”.
In the third query, you can not make strings s and t equal. Therefore, the answer is “NO”.
理解:

这里是引用

#include<iostream>
#include<cstdio>
#include<set>
using namespace std;
int main()
{
	int n;
	cin>>n;

	while(n--)
	{
		string  a,b;
		cin>>a>>b;
		set<char> ss;
		set<char> s;
		set<char> t;
		int L1=a.size(),L2=b.size();
		
		for(int i=0;i<L1;i++)
		{
			
			ss.insert(a[i]);
			t.insert(a[i]);
		}
		for(int i=0;i<L2;i++)
		{
			s.insert(b[i]);
			t.insert(b[i]);
		}
		if(t.size()<ss.size()+s.size())
		{
			cout<<"YES"<<endl;
		}
		else
			cout<<"NO"<<endl;
	}
	return 0;	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值