Пример #1
0
int main(int argc, char* argv[]){
	if (argc != 4){
		cout << "Correct Syntax: program3 <input_file_1> <input_file_2> <output_file>" << endl;
		return -1;
	}
	ifstream inFile1 (argv[1]);
	ifstream inFile2 (argv[2]);
	ofstream outfile (argv[3]);

	//Determine the size of each file
	if (!inFile1.is_open() || !inFile2.is_open()){
		cout << "ERROR: One of the input files doesn't exist" << endl;
		return -2;
	}
	string input1;
	string input2;
	inFile1 >> input1;
	inFile2 >> input2;
	int inputALength = input1.length();
	int inputBLength = input2.length();	
	int rowsize = inputALength + 1;
	int colsize = inputBLength + 1;
	char* cinput1 = (char*)input1.c_str();
	char* cinput2 = (char*)input2.c_str();

	//Create a LCS object
	LCS* myLCS = new LCS(rowsize, colsize, inputALength, inputBLength, cinput1, cinput2);
	clock_t t;
	t = clock();
	int lcs_size = myLCS->find_lcs();
	t = clock() - t;
	outfile << lcs_size << endl;
	outfile << ((float)t)/CLOCKS_PER_SEC << endl;
	return 0;
}
Пример #2
0
int main()
{
	string A="1A2C3D4B56",B="B1D23CA45B6A";
	LCS f;
	cout<<f.findLCS(A,10,B,12);
	return 0;
}
Пример #3
0
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   <Diff analysis algoritms>   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/// Método que analiza os 2 ficheiros actualziando as estruturas auxiliares necessárias para fazer o output da diferença entre eles
void Diff::analyzeFiles() {
    findCorrespondentLines();

    for (size_t lineIndex = 0; lineIndex < originalFileLinesStatus.size(); ++lineIndex) {
        LCS lcs;
        string LCSFound;

        if (originalFileLinesStatus[lineIndex].getLinesStatus() == LINE_MODIFIED) {
            lcs = LCS(originalFileData[lineIndex], modifiedFileData[lineIndex]);
            LCSFound = lcs.findLCS();
        }

        if (originalFileLinesStatus[lineIndex].getLinesStatus() == LINE_MOVED_AND_MODIFIED) {
            lcs = LCS(originalFileData[lineIndex], modifiedFileData[originalFileMovedLinesIndexsInModifiedFile[lineIndex]]);
            LCSFound = lcs.findLCS();
        }

        if (LCSFound.empty())
            continue;

        //update aos infos dos chars da linha do ficheiro original
        size_t currentPosOnLCS = 0;
        vector <bool> lineCharsChangedOnOriginalFile(originalFileData[lineIndex].size(), true);
        for (size_t charIndex = 0; charIndex < originalFileData[lineIndex].size(); ++charIndex) {
            if (currentPosOnLCS < LCSFound.size()) {
                if (LCSFound[currentPosOnLCS] == originalFileData[lineIndex][charIndex]) {
                    lineCharsChangedOnOriginalFile[charIndex] = false;
                    ++currentPosOnLCS;
                }
            } else {
                break;
            }
        }

        originalFileLinesStatus[lineIndex].setLineCharsChangedOnOriginalFile(lineCharsChangedOnOriginalFile);



        //update aos infos dos chars da linha do ficheiro modificado
        currentPosOnLCS = 0;
        int indexOfOriginalLineOnModifiedFile = originalFileMovedLinesIndexsInModifiedFile[lineIndex];
        vector <bool> lineCharsChangedOnModifiedFile(modifiedFileData[indexOfOriginalLineOnModifiedFile].size(), true);
        for (size_t charIndex = 0; charIndex < modifiedFileData[indexOfOriginalLineOnModifiedFile].size(); ++charIndex) {
            if (currentPosOnLCS < LCSFound.size()) {
                if (LCSFound[currentPosOnLCS] == modifiedFileData[indexOfOriginalLineOnModifiedFile][charIndex]) {
                    lineCharsChangedOnModifiedFile[charIndex] = false;
                    ++currentPosOnLCS;
                }
            } else {
                break;
            }
        }

        originalFileLinesStatus[lineIndex].setLineCharsChangedOnModifiedFile(lineCharsChangedOnModifiedFile);


    }
}
int main()
{
    LCS l ;
    l.read_write() ;
    return 0 ;
}