Skip to content
Snippets Groups Projects
Commit 24fa4b35 authored by Eduardo Machado's avatar Eduardo Machado
Browse files

funcionando por enquanto

parent 96ad6782
No related branches found
No related tags found
No related merge requests found
......@@ -12,4 +12,4 @@
using namespace std;
int* pack(string input);
string unpack(int* input);
\ No newline at end of file
string unpack(int* input, int size);
\ No newline at end of file
......@@ -40,10 +40,10 @@ int* pack(string input){
}
string unpack(int* input){
string unpack(int* input, int size){
map<int, string> dictionary;
string currentChar, nextChar, output = "";
int i, size, dictionarySize = 256;
int i, dictionarySize = 256;
int currentWord, nextWord;
//inicializa o dicionário
......@@ -53,19 +53,18 @@ string unpack(int* input){
nextWord = input[0];
output += dictionary[nextWord];
size = sizeof(input)/sizeof(int);
for(i = 0; i < size; i++){
for(i = 0; i < size-1; i++){
currentWord = nextWord;
nextWord = input[i+1];
if(dictionary[nextWord] != ""){
output += dictionary[nextWord];
currentChar = dictionary[currentWord];
nextChar = dictionary[nextWord][1];
nextChar = dictionary[nextWord][0];
dictionary[dictionarySize] = currentChar + nextChar;
dictionarySize++;
}else{
currentChar = dictionary[currentWord];
nextChar = dictionary[currentWord][1];
nextChar = dictionary[currentWord][0];
output += currentChar + nextChar;
dictionary[dictionarySize] = currentChar + nextChar;
dictionarySize++;
......
......@@ -59,8 +59,7 @@ int main(int argc, char *argv[])
}
// Descompactação.
outputUnpack = unpack(inputUnpack);
cout << "outputUnpack = " << outputUnpack << endl;
outputUnpack = unpack(inputUnpack, length/4);
// Escrita no arquivo de saída.
fileOut.open(nameFileOut.c_str(), ios::out);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment