PAT 1012

在这里插入图片描述

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
            arr[i] = in.nextInt();
        
        int countA1 = 0, countA2 = 0, countA3 = 0, countA4 = 0, countA5 = 0;
        int sumA1 = 0, sumA2 = 0,max = 0;
        double sumA4 = 0;
        for(int i =0; i < n; i++) {
            int temp = arr[i];
            if(temp % 5 == 0){
                if(temp % 2 == 0){
                    sumA1 += temp;
                    countA1 += 1;
                }
            }
            
            if(temp % 5 == 1){
                if(countA2 % 2 == 0)
                    sumA2 += temp;
                else
                    sumA2 -= temp;
                countA2 += 1;
            }
            
            if(temp % 5 == 2){
                countA3 += 1;
            }
            
            if(temp % 5 == 3){
                sumA4 += temp;
                countA4 += 1;
            }
            
            if(temp % 5 == 4){
                if(temp > max)
                    max = temp;
                countA5 += 1;
            }
        }
        
        if(countA1 == 0)
            System.out.print("N");
        else
            System.out.print(sumA1 );
        
        if(countA2 == 0)
            System.out.print(" N");
        else
            System.out.print(" " + sumA2 );
        
        if(countA3 == 0)
            System.out.print(" N");
        else
            System.out.print(" " + countA3);
        
        if(countA4 == 0)
            System.out.print(" N");
        else
            /*
                这里有一个小点:想%.1f输出 int/int 的结果一定会错
                要不就定义为double再double/int
                要不就(int * 1.0) int
            */
            System.out.printf(" %.1f",sumA4/countA4);
        
        if(countA5 == 0)
            System.out.print(" N");
        else
            System.out.print(" " + max);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值