PAT(Basic Level) Practice(中文) 1012

【Basic Level】
*1012 输出N的条件判断

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip> // cout << setiosflags(ios::fixed) << setprecision(n);
using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    int a = 0, b = 0, c = 0, f = 0;
    int t = 0;
    float d = 0.0, x = 0.0;
    for (int i = 0, m = 0, flag = 1; i < n; i++)
    {
        cin >> m;
        switch (m % 5)
        {
        case 0:
            if (m % 2 == 0)
                a += m;
            break;
        case 1:
            if (flag)
            {
                b = b + m;
                flag = 0;
            }
            else
            {
                b = b - m;
                flag = 1;
            }
            break;
        case 2:
            c++;
            break;
        case 3:
            d += m;
            x++;
            break;
        case 4:
            f = m > f ? m : f;
            break;

        default:
            break;
        }
    }
    if (a != 0)  cout << a << " ";
    else  cout << "N ";

    if (t)  cout << b << " ";
    else  cout << "N ";

    if (c != 0) cout << c << " ";
    else  cout << "N ";

    if (d != 0)  cout << setiosflags(ios::fixed) << setprecision(1) << d / x << " ";
    else  cout << "N ";

    if (f != 0)  cout << f << endl;
    else  cout << "N" << endl;

    //system("pause");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值