1012 数字分类 (20)(20 分)

#include
#include
#include
using namespace std;
int n, x;
vectora[6];
int main()
{
	scanf("%d", &n);
	while (n--)
	{
		scanf("%d", &x);
		if (x % 5 == 0&&x%2==0)a[1].push_back(x);
		else if (x % 5 == 1)a[2].push_back(x);
		else if (x % 5 == 2)a[3].push_back(x);
		else if (x % 5 == 3)a[4].push_back(x);
		else if (x % 5 == 4)a[5].push_back(x);
	}
	if (a[1].size() == 0)printf("N ");
	else
	{
		int sum = 0;
		for (int i = 0; i < a[1].size(); i++)sum += a[1][i];
		printf("%d ", sum);
	}
	if (a[2].size() == 0)printf("N ");
	else
	{
		int sum = 0;
		for (int i = 0; i < a[2].size(); i++)
		{
			if (i % 2 == 0)sum += a[2][i];
			else sum -= a[2][i];
		}
		printf("%d ", sum);
	}
	if (a[3].size() == 0)printf("N ");
	else printf("%d ", a[3].size());
	if (a[4].size() == 0)printf("N ");
	else
	{
		double ans = 0;
		for (int i = 0; i < a[4].size(); i++)ans += a[4][i];
		printf("%.1f ", ans / a[4].size());
	}
	if (a[5].size() == 0)printf("N");
	else
	{
		int k = 0;
		for (int i = 0; i < a[5].size(); i++)if (a[5][k] < a[5][i])k = i;
		printf("%d", a[5][k]);
	}
	return 0;
}

 

你可能感兴趣的:(PAT乙级真题)