XOR and OR

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   java   os   io   

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64uSubmit Status Practice CodeForces 282C

Description

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 q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and 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.

Sample Input

11
10
YES

1

01
NO

000

101
NO

分析:

      如果數的長度不一樣,肯定不行則為NO;如果為1和0 便可以轉換;除了0 0以外,其他的數肯定不會變為0 0,NO 。

兩邊有1的都是YES,兩邊全是0的也是YES。

代碼:

#include<stdio.h>#include<string.h>char a[1000001],b[1000001];int main(){    int len1,len2,i,j,f1,f2;    while(~scanf("%s %s",a,b))    {        len1=strlen(a);        len2=strlen(b);        if(len1!=len2)           printf("NO\n");        else        {            f1=f2=0;        for(i=0;i<len1;i++)        {            if(a[i]==‘1‘)               f1++;        }        for(i=0;i<len2;i++)        {            if(b[i]==‘1‘)               f2++;        }        if(f1==0&&f2==0)            printf("YES\n");        else if(f1!=0&&f2!=0)            printf("YES\n");        else            printf("NO\n");        }        }    return 0;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.