<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. START
  3. READ the first line of the INPUT
  4. and STORE as many number of player 1 cards
  5. READ the second line of INPUT
  6. and STORE as many number of player 1 cards
  7. READ the third line of the INPUT
  8. and STORE as many number of player 2 cards
  9. READ the fourth line of INPUT
  10. and STORE as many number of player 2 cards
  11.  
  12. ORDER the cards of player 1 and player 2 from highest to lowest
  13.  
  14. WHILE there is no winner or draw
  15. Check the number of cards in player 1
  16. Check the number of cards in player 2
  17.  
  18. IF player 1 and player 2 do not have cards
  19. THEN save output as 'Draw'
  20. END IF
  21.  
  22. IF player 2 does not have cards
  23. THEN save output as 'player 1 wins'
  24. END IF
  25.  
  26. IF player 1 does not have cards
  27. THEN save output as 'player 2 wins'
  28. END IF
  29.  
  30. Take out a card from player 1
  31. Take out a card from player 2
  32.  
  33. IF player 1's card is greater than player 2's
  34. THEN save output as 'player 1 wins'
  35. END IF
  36.    
  37. IF the card of player 1 is equal to that of player 2
  38. THEN Continue cycle with next turn
  39. ELSE save output as 'player 2 wins’
  40. END IF
  41.  
  42. END WHILE
  43.  
  44. PRINT output of game
  45. END
  46. */
  47.  
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51.  
  52.  
  53. void readCards( const int numCards, const int* cards )
  54. {
  55.    int index;
  56.    for( index = 0; index < numCards; index++ )
  57.    {
  58.       scanf( "%d", &cards[index] );
  59.    }
  60. }
  61.  
  62. void sortCards( int* const cards, const int numCards )
  63. {
  64.    int i, j, temp;
  65.    for (i = 1; i < numCards; i++)
  66.    {
  67.       for (j = 0; j < numCards - 1; j++)
  68.       {
  69.          if ( cards[j] < cards[j+1])
  70.          {
  71.             temp = cards[j];
  72.             cards[j] = cards[j+1];
  73.             cards[j+1] = temp;
  74.          }
  75.       }
  76.    }
  77. }
  78.  
  79. int main(int argc, char *argv[])
  80. {
  81.    int cardNumJ1;
  82.    int cardNumJ2;
  83.    int cardsJ1[10];
  84.    int cardsJ2[10];
  85.    int index;
  86.    int turn = 0;
  87.    char output[30];
  88.    
  89.    scanf( "%d", &cardNumJ1 )
  90.    readCards(cardNumJ1, cardsJ1);
  91.    scanf( "%d", &cardNumJ2 );
  92.    readCards(cardNumJ2, cardsJ2);
  93.    sortCards( cardsJ1, cardNumJ1 );
  94.    sortCards( cardsJ2, cardNumJ2 );
  95.    
  96.    
  97.    while( 1 )
  98.    
  99.    {
  100.       
  101.       if( cardNumJ1 - turn <= 0 && cardNumJ2 - turn <= 0 )
  102.       {
  103.          strcpy( output, "Draw");
  104.          break;
  105.       }
  106.      
  107.       if( cardNumJ2 - turn <= 0 )
  108.       {
  109.          strcpy( output, "Player 1 wins");
  110.          break;
  111.       }
  112.       
  113.       
  114.       if( cardNumJ1 - turn <= 0 )
  115.       {
  116.          strcpy( output, "Player 2 wins");
  117.          break;
  118.       }
  119.      
  120.       if( cardsJ1[turn] > cardsJ2[turn] )
  121.       {
  122.          strcpy( output, "Player 1 wins");
  123.          break;
  124.       }
  125.       
  126.       if( cardsJ2[turn] > cardsJ1[turn] )
  127.       {
  128.          strcpy( output, "Player 2 wins");
  129.          break;   
  130.       }
  131.       
  132.       turn++;   
  133.    }
  134.    
  135.    
  136.    printf("%s", output);
  137.    
  138.    
  139.    return 0;
  140. }