-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlcs.cpp
More file actions
67 lines (51 loc) · 1.39 KB
/
Copy pathlcs.cpp
File metadata and controls
67 lines (51 loc) · 1.39 KB
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
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include "lcs.h"
const char* usage = "Usage:\n lcs <file> <file>\n";
using namespace std;
template < typename T >
void run_lcs(vector<T> &o, vector<T> &n)
{
clock_t start_time = clock();
vector<T> LCS(n.size());
typename vector<T>::iterator end = lcs(o.begin(), o.end(),
n.begin(), n.end(),
LCS.begin());
clock_t end_time = clock();
LCS.resize(end-LCS.begin());
cout << string(LCS.begin(), LCS.end());
double cpu_time_secs = ((end_time - start_time)/(double)CLOCKS_PER_SEC)*1000;
cerr << " Time spent = " << cpu_time_secs <<" ms\n";
}
vector<char> * read_ascii_file (string name)
{
FILE * f = fopen (name.c_str(), "r");
if (f == NULL) perror("fopen");
int err = fseek(f, 0, SEEK_END) != 0;
if (err) perror("fseek");
int fSize=ftell(f);
if (fSize < 0) perror("ftell");
rewind(f);
vector<char> *bufferp=new vector<char>;
bufferp->resize(fSize);
err = fread (&((*bufferp)[0]), 1, fSize, f);
if (err < 0) perror ("fread");
fclose (f);
return bufferp;
}
int main(int argc, char* argv[]) {
if (argc < 3){
fprintf(stderr, "%s", usage);
exit(-1);
}
vector<char> * lisp = read_ascii_file(argv[1]);
vector<char> * lisp1 = read_ascii_file(argv[2]);
run_lcs<char>(*lisp, *lisp1);
delete lisp;
delete lisp1;
return 0;
}