#include<stdio.h>
#include<stdlib.h>
void winnerSelect(int a[], int size, int max)
{
int i;
int maxVote,winCandidate;
int *candidate;
candidate=(int*)malloc(sizeof(int)*max);
for(i=0;i<=max;i++)
{
candidate[i]=0;
}
maxVote=0;
winCandidate=a[0];
for(i=0;i<size;i++)
{
candidate[a[i]]++;
if(candidate[a[i]]>maxVote)
{
maxVote=candidate[a[i]];
winCandidate=a[i];
}
}
printf("Max vote: %d\nWinner candidate : %d\n",maxVote,winCandidate);
free(candidate);
}
int main()
{
int a[]={10,12,11,23,23,12,12,11,11,34};
int size = sizeof(a)/sizeof(int);
int max=0,i;
for(i=0;i<size;i++)
{
if(a[i]>max)
max=a[i];
else
max=max;
}
winnerSelect(a,size,max);
printf("Size: %d Max : %d",size,max);
}
No comments:
Post a Comment