题解 | #位操作练习#

位操作练习

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")

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务