fork(1) download
  1. #include <iostream>
  2.  
  3. enum suit {hearts, diamonds, spades, clubs};
  4. enum value {two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace};
  5.  
  6. struct card
  7. {
  8. value v;
  9. suit s;
  10. };
  11. static const int num_players = 4;
  12.  
  13. static const char* suits[] = {"Hearts", "Diamonds", "Spades", "Clubs"};
  14. static const char* values[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
  15.  
  16. std::ostream& operator<<(std::ostream &out, const card &c)
  17. {
  18. out << values[c.v] << " of " << suits[c.s];
  19. return out;
  20. }
  21.  
  22. void get_winner(const card (*hands)[num_players][2], const card (*mid_cards)[5])
  23. {
  24. for (int i = 0; i < 5; i++) {
  25. std::cout << "Middle card " << i + 1 << ": " << (*mid_cards)[i] << "\n";
  26. }
  27.  
  28. for (int i = 0; i < num_players; i++) {
  29. std::cout << "Player " << i + 1 << "hand: " << (*hands)[i][0] << ", " << (*hands)[i][1] << "\n";
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. card hands[num_players][2];
  36. card mid_cards[5];
  37. // fill hands and mid_cards with card structs
  38. hands[0][0] = card {jack, hearts};
  39. hands[0][1] = card {nine, spades};
  40. hands[1][0] = card {ace, clubs};
  41. hands[1][1] = card {ace, hearts};
  42. hands[2][0] = card {three, diamonds};
  43. hands[2][1] = card {seven, spades};
  44. hands[3][0] = card {eight, diamonds};
  45. hands[3][1] = card {nine, clubs};
  46. mid_cards[0] = card {five, clubs};
  47. mid_cards[1] = card {king, hearts};
  48. mid_cards[2] = card {queen, spades};
  49. mid_cards[3] = card {two, clubs};
  50. mid_cards[4] = card {ace, hearts};
  51. get_winner(&hands, &mid_cards);
  52. }
Success #stdin #stdout 0.01s 5380KB
stdin
Standard input is empty
stdout
Middle card 1: 5 of Clubs
Middle card 2: King of Hearts
Middle card 3: Queen of Spades
Middle card 4: 2 of Clubs
Middle card 5: Ace of Hearts
Player 1hand: Jack of Hearts, 9 of Spades
Player 2hand: Ace of Clubs, Ace of Hearts
Player 3hand: 3 of Diamonds, 7 of Spades
Player 4hand: 8 of Diamonds, 9 of Clubs