[PAT]1012 数字分类
PAT (Basic Level) Practice 1012 数字分类 https://pintia.cn/pr...

22
2019/08

# [PAT]1012 数字分类

PAT (Basic Level) Practice 1012 数字分类
https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840

## 分析

2
6 6
N N N N N

## java代码

package PAT.BasicLevel;

import java.util.Scanner;

public class _1002数字分类 {
public static void main(String[] args) {
int A1,A2,A3,A5;
double A4;
A1=A2=A3=A5=0;
A4=0;
int A4count=0;
Scanner cin =new Scanner(System.in);
int n=cin.nextInt();
boolean yesn=true;
for(int i=0;i<n;i++){
int x=cin.nextInt();
if(x%5==0&&x%2==0){
A1+=x;
}else
if(x%5==1){
if(yesn) yesn=false;
else A2-=x;
}else
if(x%5==2){
A3++;
}else
if(x%5==3){
A4+=x;
A4count++;
}else
if(x%5==4){
if(x>A5) A5=x;
}
}

if(A1==0){
System.out.print("N ");
}else
System.out.print(A1+" ");
if(yesn){
System.out.print("N ");
}else
System.out.print(A2+" ");
if(A3==0){
System.out.print("N ");
}else
System.out.print(A3+" ");
if(A4count==0){
System.out.print("N ");
}else {
A4 /= A4count;
System.out.printf("%.1f ", A4);
}
if(A5==0){
System.out.print("N");
}else
System.out.print(A5);
//若其中某一类数字不存在，则在相应位置输出“N”。

}
}

百度已收录

Last modification：August 22nd, 2019 at 10:07 pm