PAT乙级1012 数字分类 (20分)

#pragma warning(disable:4996)
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

bool cmp(int a, int b)
{
	return a < b;
}

int main()
{
	int n;
	scanf("%d", &n);
	int  a5[1010];
	int  a1p = 0, a2p=0,a2pp = 1, a3p = 0, a4p = 0, a5p = 0;
	int a1sum = 0, a2sum = 0, a4sum = 0;
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf("%d", &temp);
		if (temp % 5 == 0)
		{
			if (temp % 2 == 0)
			{
				a1sum = a1sum + temp;
				a1p++;
			}
		}
		else if (temp % 5 == 1)
		{
			a2sum = a2sum + a2pp * temp;
			a2pp = -1 * a2pp;
			a2p++;
		}
		else if (temp % 5 == 2)
		{
			a3p++;
		}
		else if (temp % 5 == 3)
		{
			a4sum = a4sum + temp;
			a4p++;
		}
		else if (temp % 5 == 4)
		{
			a5[a5p] = temp;
			a5p++;
		}
	}
	if (a5p != 0)
	{
		sort(a5, a5 + a5p-1, cmp);
	}
	if (a1p == 0)
		printf("N ");
	else
		printf("%d ",a1sum);
	if (a2p == 0)
		printf("N ");
	else
		printf("%d ", a2sum);
	if (a3p == 0)
		printf("N ");
	else
		printf("%d ", a3p);
	if (a4p == 0)
		printf("N ");
	else
		printf("%.1f ", (float)a4sum/a4p);
	if (a5p == 0)
		printf("N");
	else
		printf("%d", a5[a5p - 1]);
	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值