fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ctime>
  5.  
  6. const char CARDS[] = { 'K', 'Q', 'J'};
  7.  
  8. unsigned const CARDS_SIZE = sizeof(CARDS)/sizeof(char);
  9.  
  10. void printCards(std::vector<const char*>& cards);
  11.  
  12. int main()
  13. {
  14. srand(time(0));
  15. std::vector<const char*> pCards;
  16.  
  17. for ( unsigned i = 0; i < CARDS_SIZE; ++i)
  18. {
  19. pCards.push_back(&CARDS[i]);
  20. }
  21. for ( unsigned i =0 ; i < 5; ++i)
  22. {
  23. std::random_shuffle(pCards.begin(), pCards.end());
  24. printCards(pCards);
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30.  
  31. void printCards(std::vector<const char*>& cards)
  32. {
  33. std::vector<const char*>::iterator it;
  34.  
  35. for ( it = cards.begin(); it != cards.end(); ++it)
  36. {
  37. std::cout << **it << " ";
  38. }
  39. std::cout << std::endl;
  40. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
Q J K 
J Q K 
K Q J 
K Q J 
Q J K