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;
    }
    
  • 相关阅读:
    Oracle rownum用法、分页
    Oracle 序列(查询序列的值,修改序列的值)
    Photoshop 更换证件照底色
    Oracle 新建用户、赋予权限
    Oracle-SQL 建表
    SQL decode 函数的用法
    英语词汇800常用20类
    c语言常用排序
    js时间戳总结
    Javascript之编译器
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11630138.html
Copyright © 2011-2022 走看看