fork(1) download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class tasowanie
  7. {
  8. public:
  9. tasowanie();
  10. ~tasowanie();
  11. tasowanie &shuffle();
  12. int operator[](int i)const { return tab[i]; }
  13. void show();
  14. static const int ilosc;
  15. private:
  16. int *tab;
  17. };
  18. const int tasowanie::ilosc=52;
  19.  
  20. ostream &operator<<(ostream &s,const tasowanie &T)
  21. {
  22. for(int i=0;i<tasowanie::ilosc;++i) s<<T[i]<<' ';
  23. return s;
  24. }
  25.  
  26. tasowanie::tasowanie():tab(new int[ilosc])
  27. {
  28. for(int i=0;i<ilosc;++i) tab[i]=i;
  29. }
  30.  
  31. tasowanie::~tasowanie()
  32. {
  33. delete[] tab;
  34. }
  35.  
  36. tasowanie &tasowanie::shuffle()
  37. {
  38. for(int i=ilosc;i>1;--i) swap(tab[i-1],tab[rand()%(i)]);
  39. return *this;
  40. }
  41.  
  42. //int _tmain(int argc, _TCHAR* argv[])
  43. int main()
  44. {
  45. srand(time(0));
  46. tasowanie t;
  47. cout<<t<<endl;
  48. cout<<t.shuffle()<<endl;
  49. t.shuffle();
  50. cout<<t<<endl;
  51. // cin.get();
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0 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 
39 32 24 4 5 26 12 35 41 10 25 14 7 0 3 1 47 29 9 38 37 42 15 20 31 18 23 2 51 49 17 21 22 28 46 50 40 13 30 11 19 34 27 16 36 45 8 44 48 43 33 6 
42 31 46 22 38 26 7 16 50 39 28 29 0 2 11 10 36 47 44 32 25 1 51 15 41 21 13 17 19 4 5 35 6 24 48 9 3 33 23 37 14 40 43 49 30 45 27 12 20 18 34 8