-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelection.c
More file actions
43 lines (37 loc) · 900 Bytes
/
Copy pathelection.c
File metadata and controls
43 lines (37 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>
#define MAX 10
int main()
{
char *contestants[] = {"john", "johnny", "jamie", "jackie" };
char *votes[] = { "john", "johnny", "jackie",
"johnny", "john", "jackie",
"jamie", "jamie", "john",
"johnny", "jamie", "johnny",
"john" };
int n = sizeof(contestants) / sizeof(contestants[0]);
int m = sizeof(votes) / sizeof(votes[0]);
int hash[n];
for(int i=0;i<n;i++)
hash[i] = 0;
for(int i=0;i<m;i++)
{
if(votes[i]==contestants[0])
hash[0]++;
else if(votes[i]==contestants[1])
hash[1]++;
else if(votes[i]==contestants[2])
hash[2]++;
else if(votes[i]==contestants[3])
hash[3]++;
}
int max = hash[0],ind=0;
for(int i=0;i<n;i++)
{
if(hash[i]>m)
{
m=hash[i];
ind = i;
}
}
printf("%s \n",contestants[ind]);
}