Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 300
  5.  
  6. //--------- ALOCAR O TAMANHO DOS ARQUIVOS-----------//
  7. int **aloc_lcs(int i, int j){
  8. int **aloc_int,aux1,aux2;
  9. aloc_int = (int**)calloc(i,sizeof(int*));
  10.  
  11. for(aux1 = 0; aux1 < i; aux1++){
  12. aloc_int[aux1] = (int*)calloc(i,sizeof(int));
  13. for (aux2 = 0; aux2 < j; aux2++){
  14. aloc_int[aux1][aux2] = 0;
  15. }
  16. }
  17. if (aloc_int == NULL){
  18. printf("Houve um erro\n");
  19. }
  20. /*
  21. for (int h = 0; h<i;h++){
  22. for(int g = 0; g<j;g++){
  23. printf("%p\n",&aloc_int[h][g]);}
  24. }
  25. */
  26.  
  27. return aloc_int;
  28. //----------- PRECISA FAZER A FUNÇÃO FREE -----------//
  29.  
  30. /*for(int aux3 = 0; aux3 < i; aux3++){
  31. free(aloc_int[aux3]);
  32. }
  33. free(aloc_int);
  34. }*/
  35. /*void free(char* libaloc1, char* libaloc2){
  36. free(libaloc1);
  37. free(libaloc2);
  38. //desalocar o resultado tambem
  39. }*/
  40.  
  41.  
  42.  
  43. //-------------- ABRIR ARQUIVO -------------------//
  44. void abrirarquivo(FILE *arq1, FILE *arq2, int *tam1, int *tam2, char **arquivo1, char **arquivo2){
  45. if (arq1 == NULL){
  46. printf("!!!!ERROR!!!!\n");
  47. exit;
  48. }
  49. if (arq2 == NULL){
  50. printf("!!ERROR!!\n");
  51. exit;
  52. }
  53. setbuf(stdin, NULL);
  54.  
  55. char palavra[MAX];
  56. char string1[MAX][MAX];
  57. char palavra2[MAX];
  58. char string2[MAX][MAX];
  59. int x = 0,y = 0;
  60.  
  61. setbuf(stdin, NULL);
  62.  
  63. while (fgets(palavra, MAX, arq1)){
  64. strcpy(string1[x], palavra);
  65. x++;
  66. }
  67. while (fgets(palavra2, MAX, arq2)){
  68. strcpy(string2[y], palavra2);
  69. y++;
  70. }
  71. *tam1 = x;
  72. *tam2 = y;
  73.  
  74.  
  75. **arquivo1 = string1;
  76.  
  77. }
  78.  
  79. //--------------- LCS -------------------//
  80. int **LCS(char **vetor,char **vetor2, int p, int k,int **L){
  81. //p e k sao os tamanhos de linhas do arquivo
  82. int L[p+1][k+1];
  83.  
  84. for (int i=0; i< p+1; i++) {
  85. for (int j=0; j< k+1; j++) {
  86. if (i == 0 || j == 0) {
  87. L[i][j] = 0; }
  88. else if (strcmp(vetor[i-1],vetor2[j-1]) == 0){
  89. L[i][j] = L[i-1][j-1] + 1;
  90. }
  91. else{
  92. L[i][j] = max(L[i-1][j], L[i][j-1]);
  93. }
  94. }
  95. }
  96. }
  97. //---------------IMPRIMIR O LCS -------------------//
  98. /*void lcsformatado(int L, char int **) {
  99. int index = L[p][k];
  100. char lcs[index][500];
  101. int i = p;
  102. int j = k;
  103.  
  104. while (i > 0 && j > 0){
  105. if (strcmp(vetor[i-1],vetor2[j-1]) == 0){
  106. strcpy(lcs[index-1],vetor[i-1]);
  107. i--;
  108. j--;
  109. index--;
  110. }
  111. else if (L[i-1][j] > L[i][j-1]){
  112. i--;
  113. }
  114. else{
  115. j--;
  116. }
  117. }
  118. for (int i=0; i < L[p][k]; i++){
  119. printf("%s",lcs[i]);
  120. }
  121.  
  122. }*/
  123.  
  124.  
  125.  
  126. int main(int argc, char* argv[ ]){
  127. FILE *arq1;
  128. FILE *arq2;
  129. arq1 = fopen(argv[1],"r");
  130. arq2 = fopen(argv[2],"r");
  131.  
  132. int tamanho1 = 0, tamanho2 = 0;
  133. abrirarquivo(arq1, arq2, &tamanho1, &tamanho2);
  134. //printf("%d %d\n",tamanho1,tamanho2);
  135. int **matriznova = aloc_lcs(tamanho1,tamanho2);
  136.  
  137. for(int r = 0 ; r<tamanho1;r++){
  138. for(int b = 0; b<tamanho2; b++){
  139. printf("%d")
  140. }
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. fclose(arq1);
  154. fclose(arq2);
  155.  
  156.  
  157.  
  158. //chamar função pra ler arquivo
  159. //retonar os arquivos lidos
  160. //chamar função pra contar o tamanho das linhas
  161. //alocar dinamicamente o tamanho das linhas
  162. //colocar cada linha em uma posição do vetor
  163. //aplicar lcs
  164. //gerar a resposta
  165. //dar free
  166. //fechar o arquivo
  167.  
  168. return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement