<mosaic.cnfolio.com>
PROGRAM
  1. /*
  2. Dim P1amntofcards as Int
  3. Dim P1value as Int
  4. Dim P2amntofcards as Int
  5. Dim P2value as Int
  6. Dim WinOrDraw as Int
  7. Console Writeline "How many cards does Player 1 have?"
  8. Console Readline P1amntofcards
  9. Console Readline P1value
  10. Console Writeline "How many cards does Player 2 have?"
  11. Console Readline P2amntofcards
  12. Console Readline P2value
  13. Sort P1amntofcards in descending order by P1value
  14. Dim Sorter as Int
  15. For i = 0,
  16. Dim No1 as Int = P1amntofcards + 1
  17. If No1 < P1amntofcards
  18. Then  Sorter = P1amntofcards
  19. P1amntofcards = No1
  20. No1 = Sorter
  21. For i = P1amntofcards,
  22. Console Writeline P1amntofcards
  23. Sort P2amntofcards in descending order by P2value
  24. Dim Sorter as Int
  25. For i = 0,
  26. No2 = Sorter
  27. For i = P1amntofcards,
  28. Console Writeline P1amntofcards
  29. While WinOrDraw = 0
  30. Check P1amntofcards and P2amntofcards
  31. If P1amntofcards = 0 and P2amntofcards = 0
  32. Then WinOrDraw = 1
  33. End If
  34. If P2amntofcards = 0
  35. Then Console writeline "Player 1 is the winner!"
  36. WinOrDraw = 2
  37. Else If P1amntofcards = 0
  38. Then Console writeline "Player 2 is the winner!"
  39. WinOrDraw = 3
  40. End If
  41. Comparing cards
  42. If P1value > P2value
  43. Then Console writeline "Player 1 is the winner!"
  44. WinOrDraw = 2
  45. Else If P1value < P2value
  46. Then Console writeline "Player 2 is the winner!"
  47. WinOrDraw = 3
  48. Else If P1value = P2value
  49. WinOrDraw = 1
  50. Next
  51. End While
  52. */
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56.  
  57.    int P1amntofcards;
  58.    int P2amntofcards;
  59.    int P1value[10];
  60.    int P2value[10];
  61.    int index;
  62.    int move = 0;
  63.    char output[30];
  64. scanf( "%d", &P1amntofcards );
  65.    cardRead(P1amntofcards, P1value);
  66.    scanf( "%d", &P2amntofcards );
  67.    cardRead(P2amntofcards, P2value);
  68.    cardSorter( P1value, P1amntofcards );
  69.    cardSorter( P2value, P2amntofcards );
  70.    while( 1 )
  71. {
  72.       if( P1amntofcards - move <= 0 && P2amntofcards - move <= 0 )
  73.       {
  74.          strcpy( output, "Draw");
  75.          break;
  76.       }
  77.  
  78.       if( P2amntofcards - move <= 0 )
  79.       {
  80.          strcpy( output, "Player 1 wins");
  81.          break;
  82.       }
  83. if( P1amntofcards - move <= 0 )
  84.       {
  85.          strcpy( output, "Player 2 wins");
  86.          break;
  87.       }
  88.       if( P1value[move] > P2value[move] )
  89.       {
  90.          strcpy( output, "Player 1 wins");
  91.          break;
  92.       }
  93.       if( P2value[move] > P1value[move] )
  94.       {
  95.          strcpy( output, "Player 2 wins");
  96.          break;
  97.       }
  98.       move++;
  99.    }
  100.    printf("%s", output);
  101.    return 0;
  102. }
  103. void cardRead( const int amntofcards, const int* cards )
  104. {
  105.    int index;
  106.    for( index = 0; index < amntofcards; index++ )
  107.    {
  108.       scanf( "%d", &cards[index] );
  109.    }
  110. }
  111.  
  112. void cardSorter( int* const cards, const int amntofcards )
  113. {
  114.    int switcher1, switcher2, switcher3;
  115.    for (switcher1 = 1; switcher1 < amntofcards; switcher1++)
  116.    {
  117. for (switcher2 = 0; switcher2 < amntofcards - 1; switcher2++)
  118.       {
  119.          if ( cards[switcher2] < cards[switcher2+1])
  120.          {
  121.             switcher3 = cards[switcher2];
  122.             cards[switcher2] = cards[switcher2+1];
  123.             cards[switcher2+1] = switcher3;
  124.          }
  125.       }
  126.    }
  127. }