#11370: 求解~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#### possible (possible)

School : 慧燈中學
ID : 54700
IP address : [114.45.44.147]
2023-10-28 14:57:29
a866. 6. Product Review Site -- | From: [114.42.137.244] | Post Date : 2016-09-17 21:58

#include <stdio.h>
int main()
{
int a,w[5]={0},s[5]={0};
for(int i=0;;i++)
{
scanf("%d",&a);
if(a==1)
w[1]++;
else if(a==2)
w[2]++;
else if(a==3)
w[3]++;
else if(a==4)
w[4]++;
else if(a==5)
w[5]++;
else
break;
}
for(int o=5;o>0;o--)
{
if(w[o]<10)
{
printf("%d ( %d) |",o,w[o]);
for(int h=0;h<w[o];h++)
{
printf("=");
}
printf("\n");
}
else if(w[o]>=10)
{
printf("%d (%d) |",o,w[o]);
for(int h=0;h<w[o];h++)
{
printf("=");
}
printf("\n");
}
}
printf("Average rating: %.4f\n",(float)(5*w[5]+4*w[4]+3*w[3]+2*w[2]+w[1])/(w[5]+w[4]+w[3]+w[2]+w[1]));
return 0;
}

#11374: Re:求解~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#### possible (possible)

School : 慧燈中學
ID : 54700
IP address : [114.45.44.147]
2023-10-28 14:57:29
a866. 6. Product Review Site -- | From: [1.162.26.7] | Post Date : 2016-09-21 13:11

#include
int main()
{
int a,w[5]={0},s[5]={0};
for(int i=0;;i++)
{
scanf("%d",&a);
if(a==1)
w[1]++;
else if(a==2)
w[2]++;
else if(a==3)
w[3]++;
else if(a==4)
w[4]++;
else if(a==5)
w[5]++;
else
break;
}
for(int o=5;o>0;o--)
{
if(w[o]<10)
{
printf("%d ( %d) |",o,w[o]);
for(int h=0;h<w[o];h++)
{
printf("=");
}
printf("\n");
}
else if(w[o]>=10)
{
printf("%d (%d) |",o,w[o]);
for(int h=0;h<w[o];h++)
{
printf("=");
}
printf("\n");
}
}
printf("Average rating: %.4f\n",(float)(5*w[5]+4*w[4]+3*w[3]+2*w[2]+w[1])/(w[5]+w[4]+w[3]+w[2]+w[1]));
return 0;
}

ZeroJudge Forum