1012

作者: 峡迩 | 来源:发表于2017-07-17 22:47 被阅读0次
    #include<iostream>
    #include<string>
    #include<vector>
    #include<iomanip>
    
    using namespace std;
    
    int a_sum(vector<int> a)
    {
        int sum = 0;
        for (auto r : a)
        {
            if (r % 2 == 0)
            {
                sum = sum + r;
            }
        }
        return sum;
    }
    int a_jc(vector<int> a)
    {
        int jc = 0;
        int sign = 1;
        for (auto r : a)
        {
            jc = jc + sign*r;
            sign = -sign;
        }
        return jc;
    }
    int a_count(vector<int> a)
    {
        return a.size();
    }
    
    double a_aver(vector<int> a)
    {
        double sum = 0.0;
        for (auto r : a)
        {
            sum = sum + r;
        }
        return sum / static_cast<double>(a.size());
    }
    
    int a_max(vector<int> a)
    {
        int max = 0;
        for (auto r : a)
        {
            if (r >= max)
                max = r;
        }
        return max;
    }
    
    int main()
    {
        vector<int> a1, a2, a3, a4, a5;
        unsigned n = 0;
        unsigned tmp;
    
        cin >> n;
        while (n > 0 && cin >> tmp)
        {
            switch (tmp%5)
            {
            case 0:
                a1.push_back(tmp);
                break;
            case 1:
                a2.push_back(tmp);
                break;
            case 2:
                a3.push_back(tmp);
                break;
            case 3:
                a4.push_back(tmp);
                break;
            case 4:
                a5.push_back(tmp);
                break;
            }
            --n;
        }
    
        if (a1.size() > 0 && a_sum(a1)!=0)
            cout << a_sum(a1) << " ";
        else
            cout << "N" << " ";
    
        if (a2.size() > 0)
            cout << a_jc(a2) << " ";
        else
            cout << "N" << " ";
    
        if (a3.size() > 0)
            cout << a_count(a3) << " ";
        else
            cout << "N" << " ";
    
        if (a4.size() > 0)
        {
            cout.setf(ios::fixed);
            cout << setprecision(1) << a_aver(a4) << " ";
        }
        else
            cout << "N" << " ";
    
        if (a5.size() > 0)
            cout << a_max(a5);
        else
            cout << "N";
    
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:1012

          本文链接:https://www.haomeiwen.com/subject/qbzqkxtx.html