Advertisement
Guest User

Untitled

a guest
May 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. int checar(int tamanho, char x[tamanho], int tamanho2, char y[tamanho2], int posicao)
  7. {
  8. if(posicao == tamanho2)
  9. {
  10. return 1;
  11. }
  12. else if(x[posicao] == y[posicao])
  13. {
  14. checar(tamanho,x,tamanho2,y,posicao+1);
  15. }
  16. else
  17. return 0;
  18.  
  19.  
  20. }
  21.  
  22. void moverString(int tamanho, char x[tamanho], int tamanho2, int posicao)
  23. {
  24. if(posicao == tamanho)
  25. {
  26. return;
  27. }
  28. else
  29. {
  30. x[posicao] = x[posicao+tamanho2];
  31. moverString(tamanho, x, tamanho2, posicao+1);
  32. }
  33. }
  34.  
  35. void comparar(int tamanho, char x[tamanho], int tamanho2, char y[tamanho2], int posicao, int posicao2)
  36. {
  37. if(posicao == tamanho)
  38. {
  39. return;
  40. }
  41.  
  42. if(x[posicao]== y[posicao2])
  43. {
  44. if(checar(tamanho,x,tamanho2,y,posicao+1))
  45. {
  46. moverString(tamanho, x, tamanho2, posicao);
  47. }
  48. }
  49. else
  50. {
  51. return comparar(tamanho, x,tamanho2, y, posicao+1, posicao2);
  52. }
  53.  
  54.  
  55. }
  56.  
  57. int main() {
  58.  
  59. char string[51];
  60. char letra[51];
  61.  
  62. scanf("%s %s", string, letra);
  63. int tamanho = strlen(string);
  64. int tamanho2 = strlen(letra);
  65.  
  66. comparar(tamanho,string,tamanho2,letra,0,0);
  67.  
  68. printf("%s\n", string);
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement