Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 300
- int max(int a, int b);
- int max(int a, int b)
- {
- if (a>b){
- return a;
- }
- else {
- return b;
- }
- }
- //--------- ALOCAR O TAMANHO DOS ARQUIVOS-----------//
- int** aloc_int(int i, int j)
- {
- int** aloc_int;
- int aux1,aux2;
- aloc_int = (int**)calloc(i,sizeof(int*));
- for(aux1 = 0; aux1 < i; aux1++)
- {
- aloc_int[aux1] = (int*)calloc(i,sizeof(int));
- for (aux2 = 0; aux2 < j; aux2++)
- {
- aloc_int[aux1][aux2] = 0;
- }
- }
- if (aloc_int == NULL)
- {
- printf("Houve um erro\n");
- }
- /*
- for (int h = 0; h<i;h++){
- for(int g = 0; g<j;g++){
- printf("%p\n",&aloc_int[h][g]);}
- }
- */
- return aloc_int;
- }
- //---------ALOCAR CHAR NA LEITURA DO ARQUIVO----------//
- char** aloc_char_lcs(int numb1, int numb2)
- {
- int** aloc_char;
- int aux1,aux2;
- aloc_char = (char**)calloc(numb1,sizeof(char*));
- for(aux1 = 0; aux1 < numb1; aux1++)
- {
- aloc_char[aux1] = (char*)calloc(numb1,sizeof(char));
- for (aux2 = 0; aux2 < numb2; aux2++)
- {
- aloc_char[aux1][aux2] = 0;
- }
- }
- if (aloc_char == NULL)
- {
- printf("Houve um erro\n");
- }
- /*
- for (int h = 0; h<i;h++){
- for(int g = 0; g<j;g++){
- printf("%p\n",&aloc_int[h][g]);}
- }
- */
- return aloc_char_lcs;
- }
- //-------------------- FREE ----------------------//
- /*void free_aloc(char** aloc_char, int** aloc_int, int tam_int)
- {
- for(int aux3 = 0; aux3 < tam_int; aux3++)
- {
- free(aloc_char[aux3]);
- }
- free(aloc_char);
- for(int aux3 = 0; aux3 < MAX; aux3++)
- {
- free(aloc_int[aux3]);
- }
- free(aloc_int);
- }
- */
- //-------------- ABRIR ARQUIVO -------------------//
- void abrirarquivo(FILE *arq, int* tamanho, char** arquivo)
- {
- if (arq == NULL)
- {
- printf("!!!!ERROR!!!!\n");
- exit;
- }
- setbuf(stdin, NULL);
- char ln_arc[MAX];
- char** aloc_char;
- int aux1,aux2;
- int ln = 0;
- arquivo = aloc_char_lcs(MAX,MAX);
- while (fgets(ln_arc, MAX, arq))
- {
- strcpy(arquivo[ln], ln_arc);
- ln++;
- }
- *tamanho = ln;
- }
- //--------------- LCS -------------------//
- /*int** LCS(char** vetor1, char** vetor2, int p, int k)
- {
- int** L = aloc_int(p+1, k+1);
- for (int i=0; i< p+1; i++) {
- for (int j=0; j< k+1; j++) {
- if (i == 0 || j == 0) {
- L[i][j] = 0; }
- else if (strcmp(vetor1[i-1],vetor2[j-1]) == 0){
- L[i][j] = L[i-1][j-1] + 1;
- }
- else{
- L[i][j] = max(L[i-1][j], L[i][j-1]);
- }
- }
- }
- return LCS;
- }*/
- //---------------IMPRIMIR O LCS -------------------//
- /*void lcsformatado(int L, char int **)
- {
- int index = L[p][k];
- char lcs[index][500];
- int i = p;
- int j = k;
- while (i > 0 && j > 0)
- {
- if (strcmp(vetor1[i-1],vetor2[j-1]) == 0)
- {
- strcpy(lcs[index-1],vetor1[i-1]);
- i--;
- j--;
- index--;
- }
- else if (L[i-1][j] > L[i][j-1])
- {
- i--;
- }
- else
- {
- j--;
- }
- }
- for (int i=0; i < L[p][k]; i++)
- {
- printf("%s",lcs[i]);
- }
- }
- */
- int main(int argc, char* argv[ ])
- {
- char **string1, **string2;
- int tamanho1 = 0, tamanho2 = 0;
- FILE *arq1;
- FILE *arq2;
- arq1 = fopen(argv[1],"r");
- arq2 = fopen(argv[2],"r");
- abrirarquivo(arq1, &tamanho1, string1);
- abrirarquivo(arq2, &tamanho2, string2);
- //LCS(tamanho1,tamanho2);
- //int **matriznova = aloc_lcs(tamanho1,tamanho2);
- printf("%s",string1[2]);
- printf("%s",string2[2]);
- //fprintf(stderr,"João me da dois pontos.\n");
- fclose(arq1);
- fclose(arq2);
- //chamar função pra ler arquivo
- //retonar os arquivos lidos
- //chamar função pra contar o tamanho das linhas
- //alocar dinamicamente o tamanho das linhas
- //colocar cada linha em uma posição do vetor
- //aplicar lcs
- //gerar a resposta
- //dar free
- //fechar o arquivo
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement