zoukankan      html  css  js  c++  java
  • XOR and OR

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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
    ");
            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
    ");
            else if(f1!=0&&f2!=0)
                printf("YES
    ");
            else
                printf("NO
    ");
            }    
        }
        return 0;
    }
  • 相关阅读:
    安装Php时候报错信息:virtual memory exhausted: Cannot allocate memory (不能分配内存)
    putty保持连接不自动段开
    利用iptables将本地的80端口请求转发到8080,当前主机ip为192.168.1.1,命令怎么写?
    linux上大量tcp端口处于TIME_WAIT的问题
    cacti出现snmp error
    洛谷3672:小清新签到题——题解
    BZOJ3040:最短路——题解
    洛谷4230:连环病原体——题解
    洛谷3934:Nephren Ruq Insania——题解
    洛谷3932:浮游大陆的68号岛——题解
  • 原文地址:https://www.cnblogs.com/lipching/p/3904041.html
Copyright © 2011-2022 走看看