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
- //--------- ALOCAR O TAMANHO DOS ARQUIVOS-----------//
- int **aloc_lcs(int i, int j){
- int **aloc_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;
- //----------- PRECISA FAZER A FUNÇÃO FREE -----------//
- /*for(int aux3 = 0; aux3 < i; aux3++){
- free(aloc_int[aux3]);
- }
- free(aloc_int);
- }*/
- /*void free(char* libaloc1, char* libaloc2){
- free(libaloc1);
- free(libaloc2);
- //desalocar o resultado tambem
- }*/
- //-------------- ABRIR ARQUIVO -------------------//
- void abrirarquivo(FILE *arq1, FILE *arq2, int *tam1, int *tam2, char **arquivo1, char **arquivo2){
- if (arq1 == NULL){
- printf("!!!!ERROR!!!!\n");
- exit;
- }
- if (arq2 == NULL){
- printf("!!ERROR!!\n");
- exit;
- }
- setbuf(stdin, NULL);
- char palavra[MAX];
- char string1[MAX][MAX];
- char palavra2[MAX];
- char string2[MAX][MAX];
- int x = 0,y = 0;
- setbuf(stdin, NULL);
- while (fgets(palavra, MAX, arq1)){
- strcpy(string1[x], palavra);
- x++;
- }
- while (fgets(palavra2, MAX, arq2)){
- strcpy(string2[y], palavra2);
- y++;
- }
- *tam1 = x;
- *tam2 = y;
- **arquivo1 = string1;
- }
- //--------------- LCS -------------------//
- int **LCS(char **vetor,char **vetor2, int p, int k,int **L){
- //p e k sao os tamanhos de linhas do arquivo
- int L[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(vetor[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]);
- }
- }
- }
- }
- //---------------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(vetor[i-1],vetor2[j-1]) == 0){
- strcpy(lcs[index-1],vetor[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[ ]){
- FILE *arq1;
- FILE *arq2;
- arq1 = fopen(argv[1],"r");
- arq2 = fopen(argv[2],"r");
- int tamanho1 = 0, tamanho2 = 0;
- abrirarquivo(arq1, arq2, &tamanho1, &tamanho2);
- //printf("%d %d\n",tamanho1,tamanho2);
- int **matriznova = aloc_lcs(tamanho1,tamanho2);
- for(int r = 0 ; r<tamanho1;r++){
- for(int b = 0; b<tamanho2; b++){
- printf("%d")
- }
- }
- 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