当前位置 : 主页 > 网页制作 > css >

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) B. Strings Equalization

来源:互联网 收集:自由互联 发布时间:2021-06-13
链接: https://codeforces.com/contest/1241/problem/B 题意: You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each oper

链接:

https://codeforces.com/contest/1241/problem/B

题意:

You are given two strings of equal length s and t 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 s is "acbc" you can get the following strings in one operation:

"aabc" (if you perform s2=s1);
"ccbc" (if you perform s1=s2);
"accc" (if you perform s3=s2 or s3=s4);
"abbc" (if you perform s2=s3);
"acbb" (if you perform s4=s3);
Note that you can also apply this operation to the string t.

Please determine whether it is possible to transform s into t, applying the operation above any number of times.

Note that you have to answer q independent queries.

思路:

s和t都能变, 直接判断是否有相同的即可.

代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int Vis[30] = {0};
        char s[200];
        cin >> s;
        int len = strlen(s);
        for (int i = 0;i <len;i++)
            Vis[s[i]-'a'] = 1;
        cin >> s;
        len = strlen(s);
        bool flag = false;
        for (int i = 0;i < len;i++)
        {
            if (Vis[s[i]-'a'])
            {
                flag = true;
                break;
            }
        }
        if (flag)
            puts("YES");
        else
            puts("NO");
    }
    
    return 0;
}
网友评论