问题 G: 数字分类 (20)

题目链接

#pragma warning(disable:4996);
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a1, a2, a3,a5;
double a4;
int main()
{
	int n;
	int f1, f2, f3, f4, f5;
	f1 = f2 = f3 = f4 = f5 = 0;//用来标识是否有该分类存在
	int temp = 1;//第二类交错求和使用
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 0;i < n;i++)
		{
			int x;
			cin >> x;
			if (x % 5 == 0 && x % 2 == 0)
			{
				f1 = 1;
				a1 += x;
			}
			if (x % 5 == 1)
			{
				f2 = 1;
				a2 += x * temp;
				temp *= -1;
			}
			if (x % 5 == 2)
			{
				f3 = 1;
				a3++;
			}
			if (x % 5 == 3) {
				f4++;
				a4 += x;
			}
			if (x % 5 == 4)
			{
				f5 = 1;
				if (a5 < x)
				{
					a5 = x;
				}
			}
		}
		if (f1 != 0) printf("%d ", a1);
		else printf("N ");
		if (f2 != 0) printf("%d ", a2);
		else printf("N ");
		if (f3 != 0) printf("%d ", a3);
		else printf("N ");
		if (f4 != 0) printf("%.1lf ", a4/f4*1.0);
		else printf("N ");
		if (f5 != 0) printf("%d\n", a5);
		else printf("N\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值