PAT1012 数字分类

给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:

#include<bits/stdc++.h>
using namespace std;
int a[1010];
//int a1[1010],a2[1010],a3[1010],a4[1010],a5[1010];
int main(){
	int N;
	scanf("%d",&N);
	int t1=0,t2=0,t3=0,t4=0,t5=0;
	int m=0;
	int mm=1;
	int nn=0;
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
		if(a[i]%5==0&&a[i]%2==0)  t1=t1+a[i];
		else if(a[i]%5==1) {
		nn++;
		t2+=mm*a[i];
		mm=mm*(-1);
		}       
		else if(a[i]%5==2)        t3++;
		else if(a[i]%5==3)  {
			t4+=a[i];
			m++;
		}
		else if(a[i]%5==4&&a[i]>t5) t5=a[i];
	}
	float t6=(float)t4/m;
//	printf("%d %d %d %.1f %d\n",t1,t2,t3,t6,t5);
    if(t1==0) printf("N ");
    else printf("%d ",t1); 
    if(nn==0) printf("N ");
    else printf("%d ",t2); 
    if(t3==0) printf("N ");
    else printf("%d ",t3); 
    if(t4==0) printf("N ");
    else printf("%.1f ",t6); 
    if(t5==0) printf("N");
    else printf("%d",t5); 
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/fionnguala1/article/details/81511939
今日推荐