OJ Brush question "Calculate the proportion of boys and girls"

Source: Internet
Author: User

Title Description

Small black to run an art school, because the last year to run the class response is good, so he expanded to 3 classes this year, he wanted to know if he did this class is more attractive to girls or boys more attractive, of course, he also want to know how many people recruit! Come on, help the black bar, you need to calculate the proportion of female students, the proportion of boys, including the number of classes, the whole school, as well as the total numbers of classes and the total number of recruits.

Input

A total of three classes, respectively, the number of boys to enter the class, girls

Output

First output the number of classes, and then output each class of boys accounted for the total number of students, girls accounted for the total number of the proportion. Finally, the total number of students, and the proportion of boys accounted for the total number of the school, girls accounted for the total number of the school.

When the scale is output, one decimal place is reserved and the total is not used.

Sample input
13 2114 2010 22
Sample output
34 0.4 0.634 0.4 0.632 0.3 0.7100 0.4 0.6

The code is as follows:

#include <iostream> #include <iomanip>using namespace Std;int main () {    int a[3][2],sum[4]={0,0,0,0},m= 0,n=0,i,j;    Double b[4][2];    for (i=0;i<3;i++)    {for        (j=0;j<2;j++)        {            cin>>a[i][j];        }    }    for (i=0;i<3;i++)    {for        (j=0;j<2;j++)        {            sum[i]+=a[i][j];        }        Sum[3]+=sum[i];        M+=A[I][0];        N+=A[I][1];    }    for (i=0;i<3;i++)    {for        (j=0;j<2;j++)        {              b[i][j]=a[i][j]*1.0/sum[i];        }    }    for (i=0; i<3; i++)    {        cout<<sum[i]<< "";        Cout<<setiosflags (ios::fixed) <<setprecision (1);        cout<<b[i][0]<< "" <<b[i][1]<<endl;    }    cout<<sum[3]<< "";    Cout<<setiosflags (ios::fixed) <<setprecision (1);    cout<<m*1.0/sum[3]<< "" <<n*1.0/sum[3]<<endl;    return 0;}

Operation Result:



This topic actually stuck me for more than half an hour, sure enough data a lot is easy to divide.




OJ Brush question "Calculate the proportion of boys and girls"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.