题解 | 位操作练习

位操作练习

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

#include <iostream>
#include <vector>
#include <algorithm>
#include<string>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b) { 
       //还有一种更简单的方法
       //注意题目已经说了长度为16位
       string x,y;
       for(int i=15;i>=0;i--){
            x+=to_string(a>>i&1);//先取出最高位
            y+=to_string(b>>i&1);
       }
       //将其中一个扩大一倍
       y+=y;
       if(y.find(x)!=string::npos){
            cout<<"YES"<<endl;
       }
       else 
            cout<<"NO"<<endl;
    }
}

全部评论

相关推荐

Kunnnnnnn:看这公司23年就成立了啊 还没倒闭呢
点赞 评论 收藏
分享
刘湘_passion:出国旅游?那就小心你的腰子咯
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务