<mosaic.cnfolio.com>
PROGRAM
1. /* START
2. Get the number of the number of cards for player 1
3. Make sure the number of cards is between 2 and 10
4. Get all the cards to sort for player 1
5. Set the position number to zero
6. WHILE the position number is 1 less than the amount of numbers
7. Look at the rest of the numbers above and find the lowest number
8. SWAP the lowest number found with current number
9. END WHILE
10. Get the number of the number of cards for player 2
11. Make sure the numberof cards is between 2 and 10
12. Get all the cards to sort for player 2
13. Set the position number to zero
14. WHILE the position number is 1 less than the amount of numbers
15. Look at the rest of the numbers above and find the lowest number
16. SWAP the lowest number found with the current number
17. END WHILE
18. WHILE both players have cards in their hands
19. Read cards from both players deck
20. IF cardA is larger than cardB
21. THEN diplay that player ! wins
22. END IF
23. ELSE
24. IF cardB is larger than cardA
25. THEN display player 2 wins
26. END IF
27. ELSE
28. IF cardA is equal to cardB
29. END IF
30. END WHILE
31. IF player 1 still has cards
32. Display player 1 wins
33. END IF
34. IF player 2 still has cards
35. Displayer player 2 wins
36. END IF
37. IF player 1 nor player 2 has cards
38. Display draw
39. END IF
40. END */
41.
42. #include <stdio.h>
43.
44. int main ( void )
45. {
46.   int numberofcardsp1;
47.   scanf( "%d", &numberofcardsp1);
48. while ((numberofcardsp1 < 2) || (numberofcardsp1 > 10))
49. {
50.     printf (" error, incorrect amount of cards ");
51.     exit(1);
52. }
53.    int card1a = 0;
54.    int counter1 = 0;
55.    if (counter1 < numberofcardsp1 )
56.    {   scanf( "%d", &card1a );
57.        counter1++; }
58.
59.    int card2a = 0;
60.    if (counter1 < numberofcardsp1)
61.    {
62.        scanf( "%d", &card2a );
63.        counter1++; }
64.
65.    int card3a = 0;
66.    if (counter1 < numberofcardsp1)
67.    {
68.      scanf( "%d" , &card3a );
69.      counter1++; }
70.
71.    int card4a = 0;
72.    if (counter1 < numberofcardsp1)
73.    {
74.      scanf( "%d" , &card4a );
75.      counter1++; }
76.
77.    int card5a =0;
78.    if (counter1 < numberofcardsp1)
79.    {
80.      scanf( "%d" , &card5a );
81.      counter1++; }
82.
83.    int card6a = 0;
84.    if (counter1 < numberofcardsp1)
85.    {
86.     scanf( "%d" , &card6a );
87.     counter1++; }
88.
89.    int card7a = 0;
90.    if (counter1 < numberofcardsp1)
91.   {
92.     scanf( "%d" , &card7a );
93.     counter1++; }
94.
95.    int card8a = 0;
96.    if (counter1 < numberofcardsp1)
97.   {
98.     scanf( "%d" , &card8a );
99.     counter1++; }
100.
101.    int card9a = 0;
102.    if (counter1 < numberofcardsp1)
103.   {
104.     scanf( "%d" , &card9a );
105.     counter1++; }
106.
107.    int card10a = 0;
108.    if (counter1 < numberofcardsp1)
109.   {
110.     scanf( "%d" , &card10a );
111.     counter1++; }
112.
113.   int outsideA, insideA, highestA, tmpSwapValueA;
114.   int cardsA[] = { card1a, card2a, card3a, card4a, card5a, card6a, card7a, card8a, card9a, card10a};
115.   for ( outsideA = 0; outsideA < (numberofcardsp1 - 1); outsideA++)
116. {
117.   highestA = outsideA;
118.  for (insideA = (outsideA + 1); insideA < numberofcardsp1; insideA++)
119.     if( cardsA[insideA] > cardsA[highestA] ) highestA = insideA;
120.
121.  tmpSwapValueA = cardsA[outsideA];
122.  cardsA[outsideA] = cardsA[highestA];
123.  cardsA[highestA] = tmpSwapValueA;
124.  }
125.  for (outsideA = 0; outsideA < numberofcardsp1; outsideA++);
126.
127.  int numberofcardsp2;
128.  scanf( "%d", &numberofcardsp2);
129.
130.  while ((numberofcardsp2 < 2) || (numberofcardsp2 > 10))
131. {
132.     printf (" error, incorrect amount of cards ");
133.     exit(1);
134. }
135.
136.  int card1b = 0;
137.  int counter2 = 0;
138.  if ( counter2 < numberofcardsp2 );
139.  {
140.   scanf( "%d", &card1b );
141.   counter2++; }
142.
143.   int card2b = 0;
144.   if (counter2 < numberofcardsp2)
145.  {
146.   scanf( "%d" , &card2b );
147.   counter2++; }
148.
149.  int card3b = 0;
150.  if (counter2 < numberofcardsp2)
151. {
152.  scanf( "%d" , &card3b );
153.  counter2++; }
154.
155.  int card4b = 0;
156.  if (counter2 < numberofcardsp2)
157. {
158.  scanf( "%d" , &card4b);
159.  counter2++; }
160.
161.  int card5b = 0;
162.  if (counter2 < numberofcardsp2)
163. {
164.  scanf( "%d" , &card5b);
165.  counter2++; }
166.
167.  int card6b = 0;
168.  if (counter2 < numberofcardsp2)
169. {
170.  scanf( "%d" , &card6b);
171.  counter2++; }
172.
173.  int card7b = 0;
174.  if (counter2 < numberofcardsp2)
175. {
176.  scanf( "%d" , &card7b);
177.  counter2++; }
178.
179.  int card8b = 0;
180.  if (counter2 < numberofcardsp2)
181. {
182.  scanf( "%d" , &card8b);
183.  counter2++; }
184.
185.  int card9b = 0;
186.  if (counter2 < numberofcardsp2)
187. {
188.  scanf( "%d" , &card9b);
189.  counter2++; }
190.
191.  int card10b = 0;
192.  if (counter2 < numberofcardsp2)
193. {
194.  scanf("%d" , &card10b);
195.  counter2++; }
196.
197.  int outsideB, insideB, highestB, tmpSwapValueB;
198.  int cardsB[] = { card1b, card2b, card3b, card4b, card5b, card6b, card7b, card8b, card9b, card10b};
199.  for ( outsideB = 0; outsideB < (numberofcardsp2 - 1); outsideB++)
200.  {
201.   highestB = outsideB;
202.
203.   for (insideB = (outsideB + 1); insideB < numberofcardsp2; insideB++)
204.    if( cardsB[insideB] > cardsB[highestB] ) highestB = insideB;
205.
206.  tmpSwapValueB = cardsB[outsideB];
207.  cardsB[outsideB] = cardsB[highestB];
208.  cardsB[highestB] = tmpSwapValueB;
209.  }
210.
211.  outsideA = 0;
212.  outsideB = 0;
213.
214.    while(( outsideA < numberofcardsp1) || ( outsideB < numberofcardsp2))
215.    {
216.     if( cardsA[outsideA] > cardsB[outsideB] ) {printf("Player 1 Wins");
217.      exit(1); }
218.     if( cardsB[outsideB] > cardsA[outsideA] ) {printf("Player 2 Wins");
219.      exit(1);}
220.     if(cardsA[outsideA] == cardsB[outsideB])
221.     outsideA++; outsideB++;
222.    }
223.
224.     if(numberofcardsp1 > numberofcardsp2) {printf("Player 1 Wins");
225.      exit(1); }
226.     if(numberofcardsp2 > numberofcardsp1) {printf("Player 2 Wins");
227.      exit(1); }
228.     if(numberofcardsp1 == numberofcardsp2) printf("Draw");
229.
230.     }