当前位置:网站首页>Haut OJ 1401: praise energy

Haut OJ 1401: praise energy

2022-07-05 05:20:00 hunziHang

Problem description :

  Tao Bao Liang 11 give the thumbs-up PK Energy gathering was very hot at that time . Just a few days. , Someone knows the secret of win-win cooperation , There are also people who fight in order to cheat praise , A lot of time was wasted for a little money . But anyway , Finally, it's time to divide up the energy of the team . The energy shared by each person is the number of likes that person has contributed to the team ( Proportion of the whole team ) In direct proportion to , The more you contribute , The more energy you get . Suppose a team has 5 personal .

Input :

The first line is the total energy integer of the team n(100<=n<=100000)
The first 2~6 Line is everyone The number of likes contributed to the team x. (0<= x <= 100000)

Output :

Output takes up one line , Output the energy shared by everyone separately ( Rounding down ), Space separates the middle

The sample input :

8000
50
30
10
10
0

Sample output :

4000 2400 800 800 0

Tips :

If two people contribute equal praise , Then they share the same energy value .


Cause analysis :

1. Be careful All contributions 0 The situation of Then divide equally .

2. Contribution points given in the example , Not by pressing 100% Calculated , Just contribute , Just give exactly equal to 100.


Solution :

#include<stdio.h>
#include<math.h>

int main()
{
    int n,a[6],s=0,b[6];
    int i;
    scanf("%d",&n);
    for(i=1;i<=5;i++)
    {
        scanf("%d",&a[i]);
        s+=a[i];
    }
    if(s==0)
        for(i=1;i<=5;i++)
        b[i]=n/5;
    else
        for(i=1;i<=5;i++)
        b[i]=n*(a[i]*1.0/s);
    for(i=1;i<=5;i++)
        printf("%d ",b[i]);
}




原网站

版权声明
本文为[hunziHang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140622509010.html