题解 | #位操作练习#

位操作练习

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

全部评论

相关推荐

点赞 评论 收藏
分享
一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:35
虽然不怎么光彩,经过这件事,可能我真的要去认同“面试八股文早该淘汰!不会用AI作弊的程序员=新时代文盲!”这句话了
HellowordX:Ai的出现是解放劳动力的,不是用来破坏公平竞争环境的,这样下去,轻则取消所有线上面试,严重了会影响整个行业对所有人产生影响,企业会拉高入职考核各种离谱考核会层出不穷
你找工作的时候用AI吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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