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
  • 相关阅读:
    iOS OC语言: Block底层实现原理 (转载)
    Objective-C中的Block(闭包) (轉載)
    http://oncenote.com/2015/09/16/Security-2-HTTPS2/ (轉載)
    iOS安全系列之一:HTTPS (轉載)
    Swif基本语法以及与OC比较三
    OC/Swift第三方添加出错解决方法
    Swift基本语法及与OC比较之二
    2015AppStore 上传步骤及常见问题
    使用AJAX日历控件,显示某些日期(CalendarExtender)
    在CheckBox中,仅仅允许选择一项
  • 原文地址:https://www.cnblogs.com/ToTOrz/p/7905708.html
Copyright © 2011-2022 走看看