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

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int total;
	int a[1000];
	int add1 = 0;
	int add2 = 0;
	double add3 = 0;
	int count = 0;
	int count1 = 0;
	double average = 0;
	int result = 0;
	cin >> total;
	int b=0;
	for(int i = 0; i < total; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < total ; i++)
	{
		if (a[i] % 5 == 0)
		{
			if (a[i] % 2 == 0)
				add1 = add1 + a[i];
		}

		if (a[i] % 5 == 1)
		{
			b++;
			if (b % 2 != 0)
				add2 = add2 + a[i];
			if (b % 2 == 0)
				add2 = add2 - a[i];
		}

		if (a[i] % 5 == 2)
		{
			count++;
		}

		if (a[i] % 5 == 3)
		{
			count1++;
			add3 = add3 + a[i];
		}

		if (a[i] % 5 == 4)
		{
			result = result > a[i] ? result : a[i];
		}

	}
	if (add1 == 0)
		cout << "N ";
	else
		cout << add1 << " ";

	if (b == 0)
		cout << "N ";
	else
		cout << add2 << " ";

	if (count == 0)
		cout << "N ";
	else
		cout << count << " ";

	if (count1 == 0)
		cout << "N ";
	else
	{
		average = add3 / count1;
		printf("%.1f ", average);
	}

	if (result == 0)
		cout << "N";
	else
		cout << result;

	system("pause");
	return 0;
}
上一篇:PTA 1012 数字的分类(20分)


下一篇:乙级PAT真题1012