Advertisement
Guest User

Untitled

a guest
Aug 18th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. // An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
  2.  
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6.  
  7. bool IsIsogram(const char *str)
  8. {
  9.     uint32_t bits;
  10.     size_t   idx;
  11.  
  12.     for(bits = idx = 0; idx < strlen(str); ++idx)
  13.         if(idx == __builtin_popcountl(bits |= 1L << (str[idx] & 0x1f)))
  14.             return false;
  15.     return true;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement