题解 | #位操作练习#

位操作练习

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

#include <stdio.h>

int main(){
    unsigned short int a,b;
    int len = sizeof(unsigned short int)*8;
    unsigned short int shifted=0;
    
    while (scanf("%hu %hu",&a,&b)==2){
        bool success=false;
        for(int i=0;i<len;i++){
            shifted = (a<<i)|(a>>len-i);
            if(shifted==b){
                success=true;
                break;
            }
        }
        if(success) printf("YES\n");
        else printf("NO\n");
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-15 10:59
已编辑
爱写代码的菜code...:哎,自己当时拿到字节offer的时候也在感叹终于拿到了,自己当时最想去的企业就是字节,结果还是阴差阳错去了鹅厂。祝uu一切顺利!!!
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务