Advertisement
EWTD

Untitled

Oct 9th, 2020 (edited)
1,662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include  <stdio.h>
  2.  
  3. int strdiff(char* a, char* b){
  4.     int index = 0;
  5.     while(a[index] != '\0' && b[index] != '\0' && a[index] == b[index])
  6.         index++;
  7.    
  8.     if(a[index] == '\0' && b[index] == '\0')
  9.         return -1;
  10.     char val = a[index]^b[index];
  11.     int i = 0;
  12.     while(val){
  13.         if(val&1)
  14.             return 8*index+i;
  15.         val = val >> 1;
  16.         i++;
  17.     }
  18. }
  19.  
  20. int main(int argc, char **argv)
  21. {
  22.         char s1[1000], s2[1000];
  23.         gets(s1);
  24.         gets(s2);
  25.         printf("%d\n", strdiff(s1, s2));
  26.  
  27.         return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement