/*This program is a solution to the question
* given by IARCS at their website.
*
* The link to the question is : http://opc.iarcs.org.in/index.php/problems/BCCSELEC
*
*Note that this solution provided below
*is in Java and not in C or C++
*/
import java.util.*;
class BCCSElection
{
public static void main()
{
System.out.println("Enter the number of people");
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
int n=sc.nextInt();
int votes[]=new int[c];
int i,v;
for(i=0;i<c;i++)
{
votes[i]=0;
}
for(i=0;i<n;i++)
{
v=sc.nextInt();
votes[v-1]++;
}
int k=0,j=0,max=0;
for(i=1;i<=3;i++)
{
for(j=0;j<c;j++)
{
if(votes[j]>=k)
{
k=votes[j];
max=j;
}
}
votes[max]=0;
k=0;
}
System.out.println(max+1);
}
}
//Author : Mayank Rajoria
* given by IARCS at their website.
*
* The link to the question is : http://opc.iarcs.org.in/index.php/problems/BCCSELEC
*
*Note that this solution provided below
*is in Java and not in C or C++
*/
import java.util.*;
class BCCSElection
{
public static void main()
{
System.out.println("Enter the number of people");
Scanner sc=new Scanner(System.in);
int c=sc.nextInt();
int n=sc.nextInt();
int votes[]=new int[c];
int i,v;
for(i=0;i<c;i++)
{
votes[i]=0;
}
for(i=0;i<n;i++)
{
v=sc.nextInt();
votes[v-1]++;
}
int k=0,j=0,max=0;
for(i=1;i<=3;i++)
{
for(j=0;j<c;j++)
{
if(votes[j]>=k)
{
k=votes[j];
max=j;
}
}
votes[max]=0;
k=0;
}
System.out.println(max+1);
}
}
//Author : Mayank Rajoria
No comments:
Post a Comment