Guest User

Untitled

a guest
Sep 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int separa (char *str1, char *str2, int tam){
  6. if(!strncmp(str1, str2, tam))
  7. return 1; /* ok = 1, entao sao iguais */
  8. else if(tam & 1)
  9. return 0; /* ok = 0, entao sao diferentes */
  10. else if(separa(str1, str2+tam/2, tam/2) && separa(str1+tam/2, str2, tam/2) || separa(str1, str2, tam/2) && separa(str1+tam/2, str2+tam/2, tam/2))
  11. return 1;
  12. else
  13. return 0;
  14. }
  15.  
  16. int main() {
  17. int tam, ok;
  18. char *str1, *str2;
  19.  
  20. scanf("%d", &tam);
  21. str1 = (char *)malloc (tam*sizeof(char));
  22. str2 = (char *)malloc (tam*sizeof(char));
  23.  
  24. while(tam != 0){
  25. str1 = (char *)realloc (str1, tam*sizeof(char));
  26. str2 = (char *)realloc (str2, tam*sizeof(char));
  27.  
  28. scanf("%s", str1);
  29. scanf("%s", str2);
  30.  
  31. ok = separa(str1, str2, tam);
  32.  
  33. if (!ok){
  34. printf("NAO\n");
  35. }
  36. else {
  37. printf ("SIM\n");
  38. }
  39. scanf("%d", &tam);
  40. }
  41.  
  42. free(str1);
  43. free(str2);
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment