题解 | #位操作练习#
位操作练习
https://www.nowcoder.com/practice/7bdc346ca39841f6a05f73d98477621d
#include<cstdio> using namespace std; void binary(int n, char arr[]) { int res; int i = 0 ; while (n != 0) { res = n / 2; arr[i] = (n - res * 2); ++i; n = n / 2; } } void swap(char x[]) { int temp = x[0]; for (int i = 0 ; i < 15 ; ++i ) { x[i] = x[i + 1]; } x[15] = temp; } bool judge(char x1[], char x2[]) { for (int i = 0; i < 15; ++i) { if (x1[i] != x2[i]) { return true; } } return false; } int main() { int n, m; while (scanf("%d%d", &n, &m) != EOF) { char x1[16] = {0}; char x2[16] = {0}; binary(n, x1); binary(m, x2); int i = 0; while ( judge(x1, x2)) { swap(x1); ++i; if (i == 16) { printf("NO\n"); return 0; }else{ i =i; } } printf("YES\n"); } return 0; }