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

B1012 数字分类 (20分)

热度:1   发布时间:2023-12-05 08:00:09.0

B1012数字分类

#include<cstdio>
int main()
{int count[5]={0};int ans[5]={0};int n,t;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&t);if(t%5==0){if(t%2==0){ans[0]=ans[0]+t;count[0]++;}}else if(t%5==1){if(count[1]%2==0){ans[1]=ans[1]+t;}else{ans[1]=ans[1]-t;}count[1]++;}else if(t%5==2){count[2]++;}else if(t%5==3){ans[3]=ans[3]+t;count[3]++;}else{if(t>ans[4]){ans[4]=t;}count[4]++;}}if(count[0]==0)printf("N ");else printf("%d ",ans[0]);if(count[1]==0)printf("N ");else printf("%d ",ans[1]);if(count[2]==0)printf("N ");else printf("%d ",count[2]);if(count[3]==0)printf("N ");else printf("%.1f ",(double)ans[3]/count[3]);if(count[4]==0)printf("N");else printf("%d",ans[4]);return 0;
}

注意:

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

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

3、最后一个不能有空格。