题解 | #位操作练习#

位操作练习

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

//转化为匹配字符串
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string intToString(int a);

int main() {
    int a, b;
    while(cin >> a >> b){
        string str_a, str_b;
        str_a = intToString(a);
        str_b = intToString(b);
        string str_c = str_a + str_a;
        if(str_c.find(str_b) != string::npos){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

string intToString(int a){
    string str = "";
    while(a != 0){
        str = to_string(a % 2) + str;
        a = a / 2;
    }
    while(str.size() < 16){
        str = "0" + str;
    }
    return str;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

榕城小榕树:1200单休,我去干点啥别的不好
点赞 评论 收藏
分享
牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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