PAT 1012 数字分类

1.需要认真看题

2.注意A2

 


#include <iostream>
#include <iomanip>
#include <stdlib.h>


using namespace std;
 

int main()
{
   
	 int k=0;
     int n;

	 cin>>n;

     int *s = (int*)malloc(sizeof(int)*n);

	 while(k<n)
     {
     	cin>>s[k++];
	 }
	 
	 int count_A2 = 0;
	 int count_A4 = 0;
	 
	 int temp_A1 = 0;
	 int temp_A2 = 0;
	 int temp_A3 = 0;
	 int temp_A4 = 0; 
	 int temp_A5 = 0;
	 
     for(int i=0;i<k;i++)
     {
     	//A1
     	if(s[i]%5==0 && s[i]%2==0)
     	{
     		temp_A1+=s[i];
		} 
		//A2
		if(s[i]%5==1)
		{
		     if(count_A2%2==0 && count_A2==0) 
			 {
			 	temp_A2 = s[i];
			 }
		     if(count_A2%2==0 && count_A2!=0)
		     {
		     	temp_A2+= s[i];
			 }
			 if(count_A2%2!=0)
			 {
			 	temp_A2-=s[i];
			 }
		     
		     count_A2++;
		}
		//A3
		if(s[i]%5==2)
		{
			temp_A3++;
		} 
		//A4
		if(s[i]%5==3)
		{
		  	temp_A4+= s[i];
			count_A4++;
		} 
		//A5
		if(s[i]%5==4)
		{
		   if(temp_A5==0)
		   {
		   	temp_A5 = s[i];
		   }
		   if(temp_A5<s[i])
		   {
		   	  temp_A5 = s[i];
		   } 
		}
		
	
	 }
	 
	 
	 
	 if(temp_A1!=0)
	 {
	 	cout<<temp_A1<<" ";
	 } 
	 else{
	 	cout<<"N ";
	 }
	 
	 
	 if(temp_A2!=0)
	 {
	 	cout<<temp_A2<<" ";
	 }
	 else if(temp_A2==0 && count_A2!=0){
	        cout<<temp_A2<<" ";
	 }else{
	 	cout<<"N "; 
	 }
	 

	 if(temp_A3!=0)
	 {
	 	cout<<temp_A3<<" ";
	 }
	 else{
	 	cout<<"N ";
	 }
	 

	 if(temp_A4!=0)
	 {
	 	//float x = float(temp_A4)/count_A4;
	    //printf("%.1f ",x);
			
	    float x = (float)temp_A4/count_A4;
	 	cout<<fixed<<setprecision(1)<<x<<" ";
	 	
	 }else{
	 	cout<<"N ";
	 }
	 
	 
	 if(temp_A5!=0)
	 {
	 	cout<<temp_A5;
	 }
	 else{
	 	cout<<"N";
	 }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值