1012. 数字分类 java,PAT-B-1012. 数字分类(Java)

package com.hym.PAT_B;

import java.util.Scanner;

/**

* Created by ymhou on 2016/11/21.

* PAT官网运行超时(100ms运行时间限制),牛客网运行通过

*/

public class PAT_B_1012 {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int N = scanner.nextInt();

int num[] = new int[N];

for(int i=0; i

num[i] = scanner.nextInt();

}

int A1=0,A2=0,A3=0,A5=0,S4=0;

double A4;

int countA4=0, count=0;

for(int i=0; i

int remainder = num[i]%5;

if(remainder==0 && num[i]%2==0){

A1 = A1 + num[i];

}

if(remainder==1){

if(count%2==0){

A2 = A2 + num[i];

}else {

A2 = A2 - num[i];

}

count++;

}

if(remainder==2){

A3++;

}

if(remainder==3){

S4 = S4 + num[i];

countA4++;

}

if(remainder==4){

if(A5

A5=num[i];

}

}

}

if(A1==0){

System.out.print("N ");

}else {

System.out.print(A1+" ");

}

if(A2==0){

System.out.print("N ");

}else {

System.out.print(A2+" ");

}

if(A3==0){

System.out.print("N ");

}else {

System.out.print(A3+" ");

}

if(S4==0){

System.out.print("N ");

}else {

A4 = 1.0*S4/countA4;

Math.round(A4);

System.out.print(String.format("%.1f",A4)+" ");

}

if(A5==0){

System.out.print("N");

}else {

System.out.print(A5);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值