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


    链接:

    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;
    }
    
  • 相关阅读:
    js前端分享功能
    git常用命令
    webstorm中.vue报错
    页面重绘重排
    浏览器渲染引擎总结
    javascript中的this总结
    cookie、session、sessionid 与jsessionid
    promise和Angular中的 $q, defer
    C++11之nullptr
    C++ 输入ctrl+z 不能再使用cin的问题
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11630138.html
Copyright © 2020-2023  润新知