Advertisement
Kocyk

bogosort stringa

Nov 8th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <windows.h>
  7. using namespace std;
  8. class Tekst{
  9. private:
  10.     int r=0;
  11.     string wejsciowy;
  12.     string aktualny;
  13. public:
  14.     unsigned long long int licznik=0;
  15.     unsigned long long int licznikmnoznik=0;
  16.     Tekst(string text)
  17.     {
  18.         wejsciowy=text;
  19.     }
  20.  
  21. void przedluzanie()
  22. {
  23.     int dl=wejsciowy.size();
  24.     for(int i=0;i<dl+1;i++)
  25.     {
  26.         aktualny[i]=i;
  27.     }
  28. }
  29. string random()
  30. {
  31.     int dl=wejsciowy.size();
  32.     int dlr=wejsciowy.size() + 1;
  33.     przedluzanie();
  34.     for(int i=0;i<dl;i++)aktualny[i]=0;
  35.     for(int i=0;i<dl;i++)
  36.      {
  37.         r=rand()%dlr;
  38.         //cout<<r<<endl;
  39.         if(aktualny[r]==0) aktualny[r]=wejsciowy[i];
  40.         else i--;
  41.        
  42.      }
  43.      for(int i=0;i<dl;i++)
  44.      {
  45.      cout<<aktualny[i];
  46.  
  47.     }
  48.      cout<<endl;
  49.         return aktualny;
  50. }
  51. bool czyinne()
  52. {
  53.     licznik++;
  54.     if(licznik==18446744073709551615) licznikmnoznik++;
  55.     int dl=wejsciowy.size();
  56.     for(int i=0;i<dl;i++)
  57.     {
  58.     if(wejsciowy[i]!=aktualny[i])return true;  
  59.     }  
  60.     return false;
  61. }
  62. };
  63. int main(int argc, char** argv) {
  64.     srand (time(NULL));
  65.     cout<<"Podaj tekst(pls nie za duzy) "<<endl;
  66.    
  67.     string str;
  68.     getline(cin,str);
  69.     cout<<"Dobra lecimy za 3..";
  70.     Sleep(1000);
  71.     cout<<"2..";
  72.     Sleep(1000);
  73.     cout<<"1..";
  74.     Sleep(1000);
  75.     cout<<"kurwa umrzesz jak dales wiecej niz 6"<<endl;
  76.     Tekst t1(str);
  77.     while(1){
  78.         t1.random();
  79.         if(t1.czyinne()==false)break;;
  80.     }
  81.     cout<<"Zajelo to tylko "<<t1.licznik<<" randomowych prob!"<<" x"<<t1.licznikmnoznik<<endl;
  82.     system("pause");
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement