zoukankan      html  css  js  c++  java
  • Codeforces 282C. XOR and OR

    The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.

    A Bitlandish string is a string made only of characters "0" and "1".

    BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and qp = x xor yq = x or y. Then he replaces one of the two taken characters by pand the other one by q.

    The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.

    So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.

    You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

    Input

    The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.

    It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

    Output

    Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

    由于10/01/11可以互相转换,所以

    对于1000000000...00可以看到除了全零串以外,其可以变成任意形式

    所以只要判断a和b是不是全零串就好了

    #include<bits/stdc++.h>  
    using namespace std;
    typedef long long LL;   
    #define SIZE 1005
    
    string a,b;
    int main(){  
        // freopen("test.in","r",stdin);
        ios::sync_with_stdio(false);
        cin >> a >> b;
        int len = a.length();
        if (len != b.length()){
            cout << "NO"; return 0;
        }
    
        int onea = 0,oneb = 0;
        for (int i=0;i<len;i++){
            if (a[i] == '1'){
                onea = 1; break;
            }
        }
        for (int i=0;i<len;i++){
            if (b[i] == '1'){
                oneb = 1; break;
            }
        }
    
        if ((onea && oneb) || !(onea || oneb)){
            cout << "YES";
        }
        else cout << "NO";
    
        return 0;   
    }  
    View Code
  • 相关阅读:
    软件测试自学建议
    软件测试-整理的自学资料
    软件测试自动化…python学习到什么程度?代码好不好学!
    软件测试为什么需要学习Linux的知识?Linux学到什么程度?-log5
    软件测试-Svn服务器搭建全过程-基于Centos6.7-64bit
    迁移虚拟机打开快照报错:CPUID错误
    软件测试-培训的套路-log3
    jaxb
    Java Sax解析
    【IOS】应用之间调用
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7905708.html
Copyright © 2011-2022 走看看