Something Similar to LCS

Well this is my assignment: https://github.com/SytemProgramming2015FallatNTU/Announcement/wiki/Homework-1
Don't worry about the due date. I'm working on drawing the table. At my current step, I want to print out the Longest Common Subsequence(the number of the same line). Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

#define MAX 10000000
#define U 1
#define L 2
#define UL 3

void fill_the_table(ifstream& file1, ifstream& file2, int **table, int **p){
  table[0][0]=0;
  p[0][0]=UL;
  string line1, line2;
  int i, j;
  while(getline(file1, line1)){
    table[0][j]=0;
    p[0][j]=L;
    while(getline(file2, line2)){
      table[i][0]=0;
      p[i][0]=L;
      if(line1==line2){
        table[i][j]=p[i-1][j-1]+1;
        p[i][j]=UL;
        i++;
      }
      else{
        if(table[i-1][j]>table[i][j-1]){
          table[i][j]=table[i-1][j];
          p[i][j]=U;
        }
        else if(table[i-1][j]<table[i][j-1]){
          table[i][j]=table[i][j-1];
          p[i][j]=L;
        }
        i++;
      }
      j++;
    }
  }
  cout<<table[i][j];
}

void table(ifstream& file1, ifstream& file2){
  int i=0, j=0;
  string line1, line2;

  while(getline(file1, line1)){
    i++;
  }
  while(getline(file2, line2)){
    j++;
  }
  int** table = new int* [i];
  for(int a=0; a<i; a++){
    table[a] = new int [j];
  }

  int** p = new int* [MAX];
  for(int a=0; a<i; a++){
    p[a] = new int [j];
  }

  fill_the_table(file1, file2, table, p);

  for(int a=0; a<i; a++){
    delete[] table[j];
  }
  delete table;

  for(int a=0; a<i; a++){
    delete[] p[j];
  }
  delete p;

  return;
}

int main(int argc, char* argv[]){
  ifstream file1(argv[1]);
  ifstream file2(argv[2]);
  table(file1, file2);
}
Topic archived. No new replies allowed.