<mosaic.cnfolio.com>
PROGRAM
1. //PSEUDO CODE
2.
3. //INTEGER FUNCTION CHECKINTEGER WITH INTEGER PARAMETER N
4. //START
5. //  IF N IS GREATER AND EQUAL THAN 1 AND LESS OR EQUAL THAN 10
6. //    RETURN VALUE IS 1
7. //  ELSE
8. //    RETURN VALUE 0
9. //END
10. //
11. //INTEGER FUCNTION CHECKQUANTITY WITH INTEGER PARAMETER N
12. //START
13. //   IF N IS GREATER AND EQUAL THAN 2 AND LESS OR EQUAL THAN 10
14. //     RETURN VALUE IS 1
15. //   ELSE
16. //RETURN VALUE 0
17. //END
18. //
19. //VOID FUNCTION SORTARRAY WITH TWO PARAMETERS: POINTER ON INTEGER(WHICH REPRESENTS AN ARRAY) AND SIZE OF AN ARRAY OF INTEGER TYPE
20. //START
21. //DECLARE TWO PARAMETERS: I,J
22. //FOR LOOP
23. //I EQUALS SIZE-1 WITH CONDITION I>0 AND DECREMENT I ON EVERY ITERATION
24. //  FOR LOOP
25. //  J EQUALS I-1 WITH CONDITION J>=0 AND DECREMENT J ON EVERY ITERATION
26. //
27. //IF THE SIZE OF THE FIRST ARRAY IS GREATER THAN THE SIZE OF THE SECOND ONE
28. //   RETURN VALUE IS 1
29. //ELSE IF THE SIZE OF THE FIRST ARRAY IS LESS THAN THE SIZE OF THE SECOND ONE
30. //   RETURN VALUE IS 2
31. //ELSE
32. //   RETURN VALUE IS 0
33. //END
34.
35. //MAIN
36. //START
37. //DECIDE TWO INTEGER VARIABLES: FIRSTQUANTITY, SECONDQUANTITY
38. //DECIDE TWO POINTERS ON INTEGER: FIRSTPLAYER, SECONDPLAYER
39. //CALL FUNCTION SORTARRAY TWO TIMES FOR EACH PLAYER
40. //DECIDE INTEGER VARIABLE AND INITIALISE IT TO RETURN VALUE OF GETWINNER FUNCTION: WINNER
41. //
42. //IF WINNER IS 1
43. //OUTPUT "PLAYER 1 WINS"
44. //
45. //IF OUTPUT IS 2
46. //OUTPUT "PLAYER 2 WINS"
47. //
48. //ELSE
49. //OUTPUT "DRAW"
50.
51.
52. #include <stdio.h>
53. #include <stdlib.h>
54.
55. int checkInteger(int n)
56. {
57.     if((n>=1 && n<=10))
58.     {
59.         return 1;
60.     }
61.     else
62.     {
63.         return 0;
64.     }
65. }
66.
67. int checkQuantity(int n)
68. {
69.     if((n>=2 && n<=10))
70.     {
71.         return 1;
72.     }
73.     else
74.     {
75.         return 0;
76.     }
77. }
78.
79. void sortArray(int *arr, int size)
80. {
81.     int i,j;
82.     for(i=size-1;i>0;--i)
83.     {
84.         for(j=i-1;j>=0;--j)
85.         {
86.             if(arr[j]<arr[i])
87.             {
88.                 int temp=arr[j];
89.                 arr[j]=arr[i];
90.                 arr[i]=temp;
91.             }
92.         }
93.     }
94. }
95.
96. int getWinner(int *arr1, int size1,int *arr2, int size2)
97. {
98.     int minSize=(size1>size2?size2:size1),i;
99.     for(i=0;i<minSize;++i)
100.     {
101.         if(arr1[i]>arr2[i])
102.         {
103.             return 1;
104.         }
105.         if(arr1[i]<arr2[i])
106.         {
107.             return 2;
108.         }
109.     }
110.
111.     if(size1>size2)
112.     {
113.         return 1;
114.     }
115.     else if(size1<size2)
116.     {
117.         return 2;
118.     }
119.
120.     return 0;
121. }
122.
123. int main()
124. {
125.     int firstQuantity,secondQuantity;
126.     int *firstPlayer, *secondPlayer;
127.
128.     while(1)
129.     {
130.         scanf("%d",&firstQuantity);
131.         if(checkQuantity(firstQuantity)==1)
132.         {
133.             break;
134.         }
135.
136.         printf("Invalid quantity is entered!!!\n");
137.     }
138.
139.     firstPlayer=(int*) (malloc(sizeof(int)*firstQuantity));
140.
141.     int i;
142.     for(i=0;i<firstQuantity;++i)
143.     {
144.         while(1)
145.         {
146.             scanf("%d",&firstPlayer[i]);
147.             if(checkInteger(firstPlayer[i])==1)
148.             {
149.                 break;
150.             }
151.
152.             printf("Invalid number is entered\n");
153.         }
154.     }
155.
156.     while(1)
157.     {
158.         scanf("%d",&secondQuantity);
159.         if(checkQuantity(secondQuantity)==1)
160.         {
161.             break;
162.         }
163.
164.         printf("Invalid quantity is entered!!!\n");
165.     }
166.
167.     secondPlayer=(int*) (malloc(sizeof(int)*secondQuantity));
168.
169.     for(i=0;i<secondQuantity;++i)
170.     {
171.         while(1)
172.         {
173.             scanf("%d",&secondPlayer[i]);
174.             if(checkInteger(secondPlayer[i])==1)
175.             {
176.                 break;
177.             }
178.
179.             printf("Invalid number is entered\n");
180.         }
181.     }
182.
183.    sortArray(firstPlayer,firstQuantity);
184.    sortArray(secondPlayer,secondQuantity);
185.
186.    int winner=getWinner(firstPlayer,firstQuantity,secondPlayer,secondQuantity);
187.    if(winner==1)
188.    {
189.        printf("Player 1 wins\n");
190.    }
191.    else if(winner==2)
192.    {
193.        printf("Player 2 wins\n");
194.    }
195.    else
196.    {
197.        printf("Draw\n");
198.    }
199. }