fork download
  1. #include <iostream>
  2.  
  3. enum suit{ HEARTS, CLUBS, DIAMONDS, SPADES };
  4. enum face{ TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE };
  5.  
  6. const char* const suitStr[4] =
  7. {
  8. "Hearts",
  9. "Clubs",
  10. "Diamonds",
  11. "Spades"
  12. };
  13.  
  14. const char* const faceStr[13] =
  15. {
  16. "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
  17. "Nine", "Ten", "Jack", "Queen", "King", "Ace"
  18. };
  19.  
  20. struct Card{
  21. suit suitType;
  22. face faceType;
  23. };
  24.  
  25. std::ostream& operator<<(std::ostream& os, const Card& c)
  26. {
  27. return os << faceStr[c.faceType] << " of " << suitStr[c.suitType];
  28. }
  29.  
  30.  
  31. typedef Card Deck[4][13];
  32.  
  33. void fillAll(Deck& fullDeck)
  34. {
  35. for (unsigned i = 0; i < 52; ++i)
  36. {
  37. suit s = suit(i / 13) ;
  38. face f = face(i % 13) ;
  39.  
  40. fullDeck[s][f].suitType = s;
  41. fullDeck[s][f].faceType = f;
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. Deck deck;
  48. fillAll(deck);
  49.  
  50. for (unsigned i = 0; i < 4; ++i)
  51. for (unsigned j = 0; j < 13; ++j)
  52. std::cout << deck[i][j] << '\n';
  53. }
  54.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Two of Hearts
Three of Hearts
Four of Hearts
Five of Hearts
Six of Hearts
Seven of Hearts
Eight of Hearts
Nine of Hearts
Ten of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
Two of Clubs
Three of Clubs
Four of Clubs
Five of Clubs
Six of Clubs
Seven of Clubs
Eight of Clubs
Nine of Clubs
Ten of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
Two of Diamonds
Three of Diamonds
Four of Diamonds
Five of Diamonds
Six of Diamonds
Seven of Diamonds
Eight of Diamonds
Nine of Diamonds
Ten of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
Two of Spades
Three of Spades
Four of Spades
Five of Spades
Six of Spades
Seven of Spades
Eight of Spades
Nine of Spades
Ten of Spades
Jack of Spades
Queen of Spades
King of Spades
Ace of Spades