<mosaic.cnfolio.com>
PROGRAM
  1. /* Each player may have 2 to 10 cards in their hand
  2. • Players may have different quantities of cards in their hand
  3. • Only numbered cards (1 to 10) are used in the game
  4. • Each player sorts the cards in their hand starting the highest card first (at the top)
  5. • Each player takes turn showing one card from their hand starting with their highest card
  6. • If one player has a higher card in a turn, the game ends and the winner is the player with
  7. the higher card
  8. • If both players have the same card, the turn ends and both players show the next highest
  9. card in their hand
  10. • If one player is out of cards, the game ends and the winner is the player that still has one or
  11. more cards in their hand
  12. • If both players are out of cards, the game ends in a draw for both players
  13.  
  14. Start of pseudocode:
  15.  
  16. Declare NumberOfPlayer1Cards as Integer
  17. Declare Player1CardValue as Integer
  18. Declare NumberOfPlayer2Cards as Integer
  19. Declare Player2CardValue as Integer
  20. Declare Winner as Boolean
  21. Declare Tie as Boolean
  22.  
  23. Print "How many cards does Player 1 have?"
  24. Input NumberOfPlayer1Cards
  25.  
  26. Input Player1CardValue
  27.  
  28. Print "How many cards does Player 2 have?"
  29. Input NumberOfPlayer2Cards
  30.  
  31. Input Player2CardValue
  32.  
  33. Sort NumberOfPlayer1Cards in descending order by Player1CardValue
  34. Sort NumberOfPlayer2Cards in descending order by Player2CardValue
  35.  
  36. While Winner = False OR Tie = False
  37.    Check NumberOfPlayer1Cards and NumberOfPlayer2Cards
  38.    
  39.    If NumberOfPlayer1Cards = 0 and NumberOfPlayer2Cards = 0
  40.    Then Tie = True
  41.    End If
  42.    
  43.    If NumberOfPlayer2Cards = 0
  44.    Then Print "Player 1 is the winner!"
  45.    Winner = True
  46.    Else If NumberOfPlayer1Cards = 0
  47.    Then Print "Player 2 is the winner!"
  48.    Winner = True
  49.    End If
  50.    
  51.  
  52.  
  53. */
  54.  
  55. void CardReader( const int NumberOfCards, const int* CardValue)
  56. {
  57.    int CardIndex;
  58.    for( CardIndex = 0; CardIndex < NumberOfCards; CardIndex++ )
  59.     {
  60.         scanf("%d", &CardValue[CardIndex]);
  61.     }
  62. }
  63. void CardSwapper(int* const CardValue, const int NumberOfCards)
  64. {
  65.     int Swapper1, Swapper2, Swapper3;
  66.     for (Swapper1 = 1; Swapper1 < NumberOfCards; Swapper1++)
  67.     {
  68.         for (Swapper2 = 0; Swapper2 < NumberOfCards - 1; Swapper2++)
  69.         {
  70.             if (CardValue[Swapper2] < CardValue[Swapper2+1])
  71.             {
  72.                 Swapper3 = CardValue[Swapper2];
  73.                 CardValue[Swapper2] = CardValue [Swapper2+1];
  74.                 CardValue[Swapper2 + 1] = Swapper3;
  75.             }
  76.         }
  77.     }
  78. }
  79.       int main(int argc, char *argv[])
  80.    {
  81.    int NumberOfPlayer1Cards;
  82.    int Player1CardValue[10];
  83.    int NumberOfPlayer2Cards;
  84.    int Player2CardValue[10];
  85.    int Winner;
  86.    int Tie;
  87.  
  88.    scanf("%d, NumberOfPlayer1Cards");
  89.    CardReader(NumberOfPlayer1Cards, Player1CardValue);
  90.    scanf("%d, NumberOfPlayer2Cards");
  91.    CardReader(NumberOfPlayer2Cards, Player2CardValue);
  92.    CardSwapper(Player1CardValue, NumberOfPlayer1Cards);
  93.    CardSwapper(Player2CardValue, NumberOfPlayer2Cards);
  94.    }
  95.  
  96.  while( 1 )
  97.    {
  98.  
  99.       if( NumberOfPlayer1Cards - turn <= 0 && NumberOfPlayer2Cards - turn <= 0 )
  100.       {
  101.          strcpy( output, "Draw");
  102.          break;
  103.       }
  104.  
  105.  
  106.       if( NumberOfPlayer2Cards - turn <= 0 )
  107.       {
  108.          strcpy( output, "Player 1 wins");
  109.          break;
  110.       }
  111.  
  112.  
  113.       if( NumberOfPlayer1Cards - turn <= 0 )
  114.       {
  115.          strcpy( output, "Player 2 wins");
  116.          break;
  117.       }
  118.  
  119.  
  120.       if( NumberOfPlayer1Cards[turn] > NumberOfPlayer2Cards[turn] )
  121.       {
  122.          strcpy( output, "Player 1 wins");
  123.          break;
  124.       }
  125.  
  126.  
  127.       if( NumberOfPlayer2Cards[turn] > NumberOfPlayer1Cards[turn] )
  128.       {
  129.          strcpy( output, "Player 2 wins");
  130.          break;
  131.       }
  132.  
  133.       turn++;
  134.    }
  135.  
  136.  
  137.    printf("%s", output);
  138.  
  139.  
  140.  
  141.    return 0;
  142. }