Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX 300
  5.  
  6.  
  7. int max(int a, int b);
  8. int max(int a, int b)
  9. {
  10. if (a>b){
  11. return a;
  12. }
  13. else {
  14. return b;
  15. }
  16. }
  17.  
  18. //--------- ALOCAR O TAMANHO DOS ARQUIVOS-----------//
  19.  
  20. int** aloc_int(int i, int j)
  21. {
  22. int** aloc_int;
  23. int aux1,aux2;
  24.  
  25. aloc_int = (int**)calloc(i,sizeof(int*));
  26. for(aux1 = 0; aux1 < i; aux1++)
  27. {
  28. aloc_int[aux1] = (int*)calloc(i,sizeof(int));
  29. for (aux2 = 0; aux2 < j; aux2++)
  30. {
  31. aloc_int[aux1][aux2] = 0;
  32. }
  33. }
  34. if (aloc_int == NULL)
  35. {
  36. printf("Houve um erro\n");
  37. }
  38. /*
  39. for (int h = 0; h<i;h++){
  40. for(int g = 0; g<j;g++){
  41. printf("%p\n",&aloc_int[h][g]);}
  42. }
  43. */
  44.  
  45. return aloc_int;
  46. }
  47. //---------ALOCAR CHAR NA LEITURA DO ARQUIVO----------//
  48.  
  49. char** aloc_char_lcs(int numb1, int numb2)
  50. {
  51. int** aloc_char;
  52. int aux1,aux2;
  53.  
  54. aloc_char = (char**)calloc(numb1,sizeof(char*));
  55. for(aux1 = 0; aux1 < numb1; aux1++)
  56. {
  57. aloc_char[aux1] = (char*)calloc(numb1,sizeof(char));
  58. for (aux2 = 0; aux2 < numb2; aux2++)
  59. {
  60. aloc_char[aux1][aux2] = 0;
  61. }
  62. }
  63. if (aloc_char == NULL)
  64. {
  65. printf("Houve um erro\n");
  66. }
  67. /*
  68. for (int h = 0; h<i;h++){
  69. for(int g = 0; g<j;g++){
  70. printf("%p\n",&aloc_int[h][g]);}
  71. }
  72. */
  73.  
  74. return aloc_char_lcs;
  75. }
  76. //-------------------- FREE ----------------------//
  77. /*void free_aloc(char** aloc_char, int** aloc_int, int tam_int)
  78. {
  79. for(int aux3 = 0; aux3 < tam_int; aux3++)
  80. {
  81. free(aloc_char[aux3]);
  82. }
  83. free(aloc_char);
  84. for(int aux3 = 0; aux3 < MAX; aux3++)
  85. {
  86. free(aloc_int[aux3]);
  87. }
  88. free(aloc_int);
  89. }
  90. */
  91. //-------------- ABRIR ARQUIVO -------------------//
  92. void abrirarquivo(FILE *arq, int* tamanho, char** arquivo)
  93. {
  94. if (arq == NULL)
  95. {
  96. printf("!!!!ERROR!!!!\n");
  97. exit;
  98. }
  99. setbuf(stdin, NULL);
  100. char ln_arc[MAX];
  101. char** aloc_char;
  102. int aux1,aux2;
  103. int ln = 0;
  104. arquivo = aloc_char_lcs(MAX,MAX);
  105. while (fgets(ln_arc, MAX, arq))
  106. {
  107. strcpy(arquivo[ln], ln_arc);
  108. ln++;
  109. }
  110. *tamanho = ln;
  111.  
  112. }
  113.  
  114. //--------------- LCS -------------------//
  115.  
  116. /*int** LCS(char** vetor1, char** vetor2, int p, int k)
  117. {
  118. int** L = aloc_int(p+1, k+1);
  119.  
  120. for (int i=0; i< p+1; i++) {
  121. for (int j=0; j< k+1; j++) {
  122. if (i == 0 || j == 0) {
  123. L[i][j] = 0; }
  124. else if (strcmp(vetor1[i-1],vetor2[j-1]) == 0){
  125. L[i][j] = L[i-1][j-1] + 1;
  126. }
  127. else{
  128. L[i][j] = max(L[i-1][j], L[i][j-1]);
  129. }
  130. }
  131. }
  132. return LCS;
  133. }*/
  134.  
  135. //---------------IMPRIMIR O LCS -------------------//
  136.  
  137. /*void lcsformatado(int L, char int **)
  138. {
  139. int index = L[p][k];
  140. char lcs[index][500];
  141. int i = p;
  142. int j = k;
  143.  
  144. while (i > 0 && j > 0)
  145. {
  146. if (strcmp(vetor1[i-1],vetor2[j-1]) == 0)
  147. {
  148. strcpy(lcs[index-1],vetor1[i-1]);
  149. i--;
  150. j--;
  151. index--;
  152. }
  153. else if (L[i-1][j] > L[i][j-1])
  154. {
  155. i--;
  156. }
  157. else
  158. {
  159. j--;
  160. }
  161. }
  162. for (int i=0; i < L[p][k]; i++)
  163. {
  164. printf("%s",lcs[i]);
  165. }
  166.  
  167. }
  168.  
  169. */
  170.  
  171. int main(int argc, char* argv[ ])
  172. {
  173. char **string1, **string2;
  174. int tamanho1 = 0, tamanho2 = 0;
  175.  
  176. FILE *arq1;
  177. FILE *arq2;
  178. arq1 = fopen(argv[1],"r");
  179. arq2 = fopen(argv[2],"r");
  180. abrirarquivo(arq1, &tamanho1, string1);
  181. abrirarquivo(arq2, &tamanho2, string2);
  182. //LCS(tamanho1,tamanho2);
  183. //int **matriznova = aloc_lcs(tamanho1,tamanho2);
  184. printf("%s",string1[2]);
  185. printf("%s",string2[2]);
  186.  
  187.  
  188.  
  189.  
  190. //fprintf(stderr,"João me da dois pontos.\n");
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. fclose(arq1);
  201. fclose(arq2);
  202.  
  203.  
  204.  
  205. //chamar função pra ler arquivo
  206. //retonar os arquivos lidos
  207. //chamar função pra contar o tamanho das linhas
  208. //alocar dinamicamente o tamanho das linhas
  209. //colocar cada linha em uma posição do vetor
  210. //aplicar lcs
  211. //gerar a resposta
  212. //dar free
  213. //fechar o arquivo
  214.  
  215. return 0;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement