Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6.  
  7. /*
  8. * Given a list of strings, find the list of characters that appear in all strings.
  9. * Here's an example:
  10. * input = ['google', 'facebook', 'youtube']
  11. * output = ['e', 'o']
  12. */
  13.  
  14. uint32_t common_characters(const char** strings, const uint32_t* lengths, const uint32_t n, char** output) {
  15. return 0;
  16. }
  17.  
  18. int main() {
  19. const int32_t n = 3;
  20. const char *(strings[]) = { "google", "facebook", "youtube" };
  21.  
  22. uint32_t lengths[n];
  23. for (int32_t i=0; i<n; ++i) {
  24. lengths[i] = strlen(strings[i]);
  25. }
  26.  
  27. char* output = NULL;
  28. uint32_t n_chars = common_characters(strings, lengths, n, &output);
  29.  
  30. for (uint32_t i=0; i<n_chars; ++i) {
  31. printf("%c ", output[i]);
  32. }
  33. printf("\n");
  34.  
  35. free(output);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement