forked from ankitkv02/procedure-oriented-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingingComp.c
More file actions
88 lines (72 loc) · 1.86 KB
/
Copy pathSingingComp.c
File metadata and controls
88 lines (72 loc) · 1.86 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<stdio.h>
#include<math.h>
#define MAX_SIZE 100
int main()
{
int N,i,j,Lower[MAX_SIZE],Upper[MAX_SIZE],Score[MAX_SIZE],Draw[MAX_SIZE],maxScore,contID,flag,drawCount;
printf("Enter the number of Contestants : ");
scanf("%d",&N);
for(i=1; i<=N; i++)
{
printf("Enter the Lower and Upper singing-pitch of Contestant No. %d : ",i);
scanf("%d%d",&Lower[i],&Upper[i]);
}
for(i=1; i<=N; i++)
{
if(Lower[i] > Upper[i])
printf("Invalid limits inserted of Contestant No. %d ! \n",i);
else
Score[i] = 0;
}
for(i=1; i<=N; i++)
{
for(j=i+1; j<=N; j++)
{
if((Lower[j] == Lower[i] && Upper[j] > Upper[i]) || (Upper[j] == Upper[i] && Lower[j] < Lower[i]) || (Lower[j] < Lower[i] && Upper[j] > Upper[i]))
Score[j] += 2;
else if((Lower[i] == Lower[j] && Upper[i] > Upper[j]) || (Upper[i] == Upper[j] && Lower[i] < Lower[j]) || (Lower[i] < Lower[j] && Upper[i] > Upper[j]))
Score[i] += 2;
else
{
Score[i] += 1;
Score[j] += 1;
}
}
}
maxScore = 0;
drawCount = 0;
for(i=1; i<=N; i++)
{
if(Score[i] > maxScore)
{
flag = 1;
maxScore = Score[i];
contID = Draw[1] = i;
drawCount = 1;
}
else if(Score[i] == maxScore)
{
flag = 0;
drawCount++;
Draw[drawCount] = i;
}
}
printf("Results are out and here! \n");
for(i=1; i<=N; i++)
printf("Contestant No. %d scores %d points \n",i,Score[i]);
if(flag == 0)
{
if(drawCount == N)
printf("The competition resulted in a draw amongst all the contestants, each scoring %d points.\n",maxScore);
else
{
printf("The competition resulted in a draw between/amongst %d people, which are Contestant No. ",drawCount);
for(i=1; i<=drawCount; i++)
printf("%d, ",Draw[i]);
printf("with %d points each. \n",maxScore);
}
}
else
printf("Contestant No. %d is the clear winner with the highest score of %d points! \n",contID,maxScore);
return 0;
}