题解 | #位操作练习#

位操作练习

https://www.nowcoder.com/practice/7bdc346ca39841f6a05f73d98477621d

#include<cstdio>
using namespace std;
void binary(int n, char arr[]) {
    int res;
    int i = 0 ;
    while (n != 0) {
        res = n / 2;
        arr[i] = (n - res * 2);
        ++i;
        n = n / 2;
    }
}
void swap(char x[]) {
    int temp = x[0];
    for (int i = 0 ; i < 15 ; ++i ) {
        x[i] = x[i + 1];
    }
    x[15] = temp;
}
bool judge(char x1[], char x2[]) {
    for (int i = 0; i < 15; ++i) {
        if (x1[i] != x2[i]) {
            return true;
        } 
    }
            return false;     
    }

int main() {
    int n, m;
    while (scanf("%d%d", &n, &m) != EOF) {
        char x1[16] = {0};
        char x2[16] = {0};
        binary(n, x1);
        binary(m, x2);
        int i = 0;
        while ( judge(x1, x2)) {
            swap(x1);
            ++i;
            if (i == 16) {
                printf("NO\n");
                return 0;
            }else{
                i =i;
            }
        }
        printf("YES\n");
    }
    return 0;
}

全部评论

相关推荐

牛客618272644号:佬携程工作怎么样,强度大吗
点赞 评论 收藏
分享
totoroyyw:千年老妖😂
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务