Untitled
unknown
plain_text
4 years ago
766 B
5
Indexable
#include <stdio.h>
#define SIZE 105
int main()
{
int n, i, g1=0, g2=0, g3=0, g4=0, teams;
int grp_size[SIZE];
printf("Enter the number of groups > ");
scanf("%d", &n);
printf("Enter the size of each group of the %d groups > ", n);
for(i=0;i<SIZE;i++)
{
scanf("%d", &grp_size[i]);
}
for(i=0; i < n; i++)
{
switch (grp_size[i])
{
case 1:
g1++;
break;
case 2:
g2++;
break;
case 3:
g3++;
break;
case 4:
g4++;
break;
}
}
teams=g4;
if (g3==g1)
{
teams+=g1;
teams+=(g2/2 + g2%2);
}
else if (g3>g1)
{
teams+=g3;
teams+=(g2/2 + g2%2);
}
else if (g1>g3)
{
teams+=g3;
int temp;
temp = g1-g3;
g2+=(g1/2);
teams+=(g2/2 + g2%2 + g1%2);
}
printf("%d", teams);
return 0;
}
Editor is loading...