#include <stdio.h> #include <stdint.h> uint8_t leftCheck(uint16_t reg, uint16_t target) { for(uint8_t x=1; x<=15;x++) { if((reg^target) == 0) return 1; uint16_t cap_bit = reg & 0x8000; cap_bit>>= 15; reg<<= 1; reg|= cap_bit; } return 0; } uint8_t rightCheck(uint16_t reg, uint16_t target) { for(uint8_t x=1; x<=15;x++) { if((reg^target) == 0) return 1; uint16_t cap_bit = reg & 0x01; cap_bit<<= 15; reg>>= 1; reg|= cap_bit; } return 0; } uint8_t is_circular_match(uint16_t reg, uint16_t target) { // Your code here if(leftCheck(reg, target)) return 1; else return(rightCheck(reg,target)); } 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