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;
    }
    
  • 相关阅读:
    最近相对闲点,写个笔记2
    最近相对闲点,写个笔记
    ORACLE 调优
    静态工厂方法与构造函数 创建类 区别
    组合与继承 区别
    Java异常
    abstract class 和 interface 区别
    java中的io系统详解
    Tomcat Apache 区别
    Vmware 下的网络模式配置
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11630138.html
Copyright © 2011-2022 走看看