Solution of 11875 - Brick Game

Problem Description
source:https://uva.onlinejudge.org/external/118/11875.html

There is a village in Bangladesh, where brick game is very popular. Brick game is a team game. Each team consists of odd number of players. Number of players must be greater than 1 but cannot be greater than 10. Age of each player must be within 11 and 20. No two players can have the same age. There is a captain for each team. The communication gap between two players depends on their age difference, i.e. the communication gap is larger if the age difference is larger. Hence they select the captain of a team in such a way so that the number of players in the team who are younger than that captain is equal to the number of players who are older than that captain. Ages of all members of the team are provided. You have to determine the age of the captain.


Input 

Input starts with an integer T (T ≤ 100), the number of test cases. Each of the next T lines will start with an integer N (1 < N < 11), number of team members followed by N space separated integers representing ages of all of the members of a team. Each of these N integers will be between 11 and 20 (inclusive). Note that, ages will be given in strictly increasing order or strictly decreasing order. We will not mention which one is increasing and which one is decreasing, you have to be careful enough to handle both situations. 

Output 

For each test case, output one line in the format ‘Case x: a’ (quotes for clarity), where x is the case number and a is the age of the captain. 

Sample Input 


5 19 17 16 14 12 
5 12 14 16 17 18 

Sample Output 

Case 1: 16 
Case 2: 16


Solution:
#include<stdio.h>
int main()
{
     int t,n,p[10],age,i,j;
     while(scanf("%d",&t)==1)
     {
        for(i=1;i<=t;i++)
        {
              scanf("%d",&n);
              for(j=1;j<=n;j++)
              {
                    scanf("%d",&p[j]);
               }
               age=p[(n+1)/2];
               printf("Case %d: %d\n",i,age);
         }
         return 0;
    }
    return 0;
}
image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience