1012 数字分类 (20分)

在这里插入图片描述

输入样例 1:

13 1 2 3 4 5 6 7 8 9 10 20 16 18      

输出样例 1:

30 11 2 9.7 9

输入样例 2:

8 1 2 4 5 6 7 9 16

输出样例 2:

N 11 2 N 9

题目分析

在这里插入图片描述
知识点:

  1. c++的保留一位小数: cout<<fixed<<setprecision(1)<<A4<<’ ';
    定义于头文件 < iomanip>
    C++标准库中的iomanip
  2. 用count1 count2 count3 count4 coun5 是否大于0 判断是否有数,是否输出’N’
  3. A2的时候可以用 sum=sum+pow(-1,count2)*b[count2];
  4. #include < algorithm>算法函数
  5. algorithm头文件常用函数
    -借鉴学习链接-
#include<iostream>
#include<iomanip>
using namespace std;

int main(){
	int n;  cin>>n;
	int arr[10000];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	//求A1=sum1
	int sum1=0,count1=0;
	for(int j=0;j<n;j++){
		if(arr[j]%5==0&&arr[j]%2==0){
			sum1+=arr[j];
			count1++;
		}
	}
	if(count1>0){
		cout<<sum1<<' ';
	}else{
		cout<<"N"<<' ';
	}
	//A2
	int sum2=0,flag=1,count2=0;
	for(int j=0;j<n;j++){
		if(arr[j]%5==1){
			count2++;
			sum2+=(flag*arr[j]);
			flag=-flag;
		}
	}
	if(count2>0){
		cout<<sum2<<' ';
	}else{
		cout<<"N"<<' ';
	}
	//A3
	int count3=0;
	for(int j=0;j<n;j++){
		if(arr[j]%5==2){
			count3++;
		}
	}
	if(count3>0)
 		cout<<count3<<" ";
 	else
 		cout<<"N"<<" ";
	//A4
	double sum4=0;
	int count4=0;
	for(int j=0;j<n;j++){
		if(arr[j]%5==3){
			sum4+=arr[j];//求和 
			count4++;
		}
	}
	double A4=sum4/count4;//求平均数 
	if(count4>0){  //注意 
		cout<<fixed<<setprecision(1)<<A4<<' ';
	}else{
		cout<<"N"<<" ";
	}
	//A5
	int max=0;
	for(int j=0;j<n;j++){
		if(arr[j]%5==4&&arr[j]>max){
			max=arr[j];
		}
	}
	if(max==0){
		cout<<"N";
	}else{
		cout<<max;
	}
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DDouble-

你的鼓励是我最大的动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值