当前位置: 代码迷 >> 综合 >> 1012 数字分类 (20 分)
  详细解决方案

1012 数字分类 (20 分)

热度:96   发布时间:2023-12-05 06:56:02.0

题目链接

思路:

1、数组count[5]用来存放五类数字的个数,初值为0

2、数组ans[5]用来存放五类数字的输出结果,初值为0

3、最后一个输出后面不能有空格

#include<iostream>
using namespace std;
const int maxn=10010;
int count[5]={0},ans[5]={0};
int main()
{int n;cin>>n;int t;for(int i=0;i<n;i++){cin>>t;if(t%5==0){if(t%2==0){ans[0]+=t;count[0]++;}}else if(t%5==1){if(count[1]%2==0){ans[1]+=t;}else{ans[1]-=t;}count[1]++;}else if(t%5==2){count[2]++;}else if(t%5==3){count[3]++;ans[3]+=t;}else {if(t>ans[4]){ans[4]=t;}count[4]++;}}if(count[0]==0)cout<<"N ";else cout<<ans[0]<<" ";if(count[1]==0)cout<<"N ";else cout<<ans[1]<<" ";if(count[2]==0)cout<<"N ";else cout<<count[2]<<" ";if(count[3]==0)cout<<"N ";else printf("%.1f ",(double)ans[3]/count[3]);if(count[4]==0)cout<<"N";else cout<<ans[4]<<endl;
}