#include <stdio.h> #include <stdint.h> uint16_t rotate_left(uint16_t reg, uint8_t len) { uint16_t tempReg = 0; tempReg |= (reg >> (16-len)); tempReg |= (reg << len); return tempReg; } uint16_t rotate_right(uint16_t reg, uint8_t len) { uint16_t tempReg = 0; tempReg |= (reg << (16-len)); tempReg |= (reg >> len); return tempReg; } uint8_t is_circular_match(uint16_t reg, uint16_t target) { // Your code here // rotate right by 1-2-3..32 & match // rotate left by 1-2-3..32 & match for (int len = 0; len <= 16; len++) { if ((target == rotate_left(reg, len)) || (target == rotate_right(reg, len))) { return 1; } } return 0; } int main() { uint16_t reg, target; scanf("%hu %hu", ®, &target); printf("%hhu", is_circular_match(reg, target)); return 0; }
Test Cases
Test Results
Input
45056 11
Expected Output
1