Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <cstdint>
  2. #include <cstdlib>
  3. #include <exception>
  4. #include <fstream>
  5. #include <ios>
  6. #include <iostream>
  7. #include <istream>
  8. #include <limits>
  9. #include <map>
  10. #include <ostream>
  11. #include <stdexcept>
  12. #include <string>
  13. #include <vector>
  14. using namespace std;
  15.  
  16.  
  17.  
  18. void dekompresja(istream &wejscie, ostream &wyjscie)
  19. {
  20.  
  21.     //1 Wypełnij słownik alfabetem źródła informacji.
  22.  
  23.     map<int,vector<char>> slownik;
  24.     int n = 0;  // n - kod ciągu (liczba)
  25.  
  26.     for(int i=0;i<256;i++){
  27.  
  28.         slownik[n]={(char)(i)};
  29.         n++;
  30.     }
  31.     char c;
  32.     wejscie.get(c);
  33.     int pk=(int)c;
  34.  
  35.     wyjscie<<(const char*)&slownik[pk];
  36.     cout<<"dochodzę prawie do pętli"<<endl;
  37.  
  38.     while(wejscie.get(c)){
  39.         cout<<"pętla"<<endl;
  40.         int k=(int)c;
  41.         vector<char*> pc;
  42.         pc.clear();
  43.  
  44.         for (int i=0; i<slownik[pk].size(); i++)
  45.         pc.push_back(slownik[pk][i]);
  46.         if(slownik.count(k)!=0)
  47.         {  
  48.             pc.push_back(slownik[k].at(0));
  49.             for (int i=0; i<pc.size(); i++)
  50.             slownik[n].push_back(pc[i]);
  51.             n++;
  52.             wyjscie<<(const char*)&slownik[k];
  53.             cout<<"przypadek1"<<endl;
  54.  
  55.         }
  56.         else
  57.         {   pc.push_back(pc.front());
  58.             for (int i=0; i<pc.size(); i++)
  59.             slownik[n].push_back(pc[i]);
  60.             n++;
  61.             wyjscie<<(const char*)&pc;
  62.             cout<<"przypadek2"<<endl;
  63.  
  64.         }
  65.         pk=k;
  66.  
  67.  
  68.  
  69.     }
  70.  
  71.  
  72. }
  73.  
  74. int main(int argc, char*argv[])
  75. {
  76.  
  77.  
  78.     //cout<<"Moze sie uda"<<endl;
  79.     ifstream plik1 (argv[1],ios_base::binary);
  80.     ofstream plik2 (argv[2],ios_base::binary);
  81.     dekompresja(plik1, plik2);
  82.  
  83.  
  84.     //return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement