zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    09-导入/导出
    django 登录
    python 数据结构
    Django 加密解密
    MySQL SQL语句
    libpython3.6m.so.1.0文件缺失
    环境变量配置
    Django 设置session过期时间
    Django 搜索功能
    表单校验
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11630138.html
Copyright © 2011-2022 走看看