<mosaic.cnfolio.com>
PROGRAM
1. /*
2. declare player_1_card_quantity
3. declare player_1_card_numbers array
4. declare player_2_card_quantity
5. declare player_2_card_numbers array
6.
7. Initialize temp_reg to 0
8. initialize total_rounds to 0
9.
11. FOR(initialize i to 0; check if i is less than player_1_card_quantity; increment i)
12.    Read all card numbers and save to array
13. ENDFOR
14.
15.
16. FOR(initialize i to 0 ; check if i is less than  player_1_card_quantity - 1 ; increment i)
17.      FOR(initialize d to 0 ;check if d is less than player_1_card_quantity - i - 1; increment d)
18.       IF (player_1_card_numbers[d] is less than player_1_card_numbers[d+1])
19.         assign temp_reg to player_1_card_numbers[d];
20.         assign player_1_card_numbers[d] to player_1_card_numbers[d+1];
21.         assign player_1_card_numbers[d+1] to temp_reg;
22.       ENDIF
23.     ENDFOR
24. ENDFOR
25.
26.
28. FOR(initialize i to 0; check if i is less than player_2_card_quantity; increment i)
29.    Read all card numbers and save to array
30. ENDFOR
31.
32.
33. FOR(initialize i to 0 ; check if i is less than ( player_2_card_quantity - 1 ); increment i)
34.      FOR(initialize d to 0 ;check if d is less than player_2_card_quantity - i - 1; increment d)
35.       IF (player_2_card_numbers[d] is less than player_2_card_numbers[d+1])
36.         assign temp_reg to player_2_card_numbers[d];
37.         assign player_2_card_numbers[d] to player_2_card_numbers[d+1];
38.         assign player_2_card_numbers[d+1] to temp_reg;
39.       ENDIF
40.     ENDFOR
41. ENDFOR
42.
43.
44.
45. IF(player_1_card_quantity is greater than or equal to player_2_card_quantity)
46.      assing total_rounds to player_2_card_quantity;
47. ELSE
48.   assign total_rounds to player_1_card_quantity;
49. ENDIF
50.
51. FOR(initilize i to 0; check if i is less than total_rounds;increment i)
52.
53.        IF(player_1_card_numbers[i] greater than player_2_card_numbers[i])
54.
55.           print "Player 1 wins!"
56.           break for loop
57.
58.        ELSEIF(player_1_card_numbers[i] less than player_2_card_numbers[i])
59.           print "Player 2 wins!"
60.           break for loop
61.
62.        ELSE
63.
64.           IF(i is equal to total_rounds-1)
65.             printf "Draw!"
66.           ENDIF
67.
68.         ENDIF
69. ENDFOR
70.
71. */
72.
73.
74.
75. #include <stdio.h>
76. //initialize some useful varialbes.
77. unsigned int player_1_card_quantity;    // stores card quantity of player 1
78. unsigned int player_1_card_numbers[10]; // stores number of cards of player 1
79. unsigned int player_2_card_quantity;    // stores card quantity of player 2
80. unsigned int player_2_card_numbers[10]; // stores number of cards of player 2
81.
82. unsigned int temp_reg=0; // stores values for a while
83. unsigned int total_rounds=0; // total rounds count
84.
85. int main()
86. {
87.     scanf("%d", &player_1_card_quantity); // read input from first line
88.     int i,d; // declare some variables
89.     for(i=0; i<player_1_card_quantity; i++) //repeat for the player 1 card quanity times
90.     {
91.
92.       scanf("%d", &player_1_card_numbers[i]); // read card numbers of player 1
93.
94.     }
95.
96.     //sorting in decreasing order
97.
98.   for (i = 0 ; i < ( player_1_card_quantity - 1 ); i++)
99.   {
100.     for (d = 0 ; d < player_1_card_quantity - i - 1; d++)
101.     {
102.       if (player_1_card_numbers[d] < player_1_card_numbers[d+1]) /* For decreasing order use < */
103.       {
104.         temp_reg = player_1_card_numbers[d]; //save currnet indexed value to temp
105.         player_1_card_numbers[d] = player_1_card_numbers[d+1]; // save greater number in previous location
106.         player_1_card_numbers[d+1] = temp_reg; //update next position with smaller number
107.       }
108.     }
109.   }
110.
111.
112.
113.     //following lines will do same tasks as player 1 did
114.     scanf("%d", &player_2_card_quantity);
115.     for(i=0; i<player_2_card_quantity;i++)
116.     {
117.
118.       scanf("%d", &player_2_card_numbers[i]);
119.
120.     }
121.
122.
123.     //sorting in decreasing order
124.
125.   for (i = 0 ; i < ( player_2_card_quantity - 1 ); i++)
126.   {
127.     for (d = 0 ; d < player_2_card_quantity - i - 1; d++)
128.     {
129.       if (player_2_card_numbers[d] < player_2_card_numbers[d+1]) /* For decreasing order use < */
130.       {
131.         temp_reg = player_2_card_numbers[d];
132.         player_2_card_numbers[d] = player_2_card_numbers[d+1];
133.         player_2_card_numbers[d+1] = temp_reg;
134.       }
135.     }
136.   }
137.
138.   if(player_1_card_quantity>=player_2_card_quantity) //check which player has more number of cards
139.      total_rounds=player_2_card_quantity; // save greater number of cards in totals rounds
140.   else
141.   total_rounds=player_1_card_quantity;
142.
143.
144.     for(i=0; i<total_rounds;i++) // repeat following code for total rounds time
145.     {
146.
147.        if(player_1_card_numbers[i]>player_2_card_numbers[i]) // if current card number of player 1 is greater than player 2
148.         {
149.
150.           printf("Player 1 wins!"); // show message of player 1 wins
151.           break; // break the for loop
152.
153.         }
154.
155.        else if(player_1_card_numbers[i]<player_2_card_numbers[i])
156.         {
157.           printf("Player 2 wins!"); //print player 2 wins message
158.           break;
159.         }
160.
161.        else //if cards are equal
162.
163.         {
164.
165.           if(i==(total_rounds-1)) // check if last round is being player
166.             printf("Draw!"); // print draw message
167.
168.         }
169.
170.     }
171.
172.     return 0;
173. }