题解 | #位操作练习#

位操作练习

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

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

void tansb(int n,string &sa){
	int i=15;
	while(n>0){
		sa[i--]=n%2+'0';
		n/=2;	
	}
}

int main(){
	int a,b,k,n;
	string sa,sb;
	sa="0000000000000000";
	sb=sa;
	cin>>a;
	cin>>b;
	tansb(a,sa);
	tansb(b,sb);
	//cout<<sa<<endl;
	//cout<<sb;
	for(int j=0;j<16;j++){
	    string t=sa;
        reverse(t.begin(),t.begin()+16);
        reverse(t.begin(),t.begin()+j);
        reverse(t.begin()+j,t.begin()+16);
        //cout<<t<<endl;
        if(t==sb){
      	cout<<"YES";
		  return 0; 
        } 
    }
    cout<<"NO";
}


全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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