输入样例 1:
13 1 2 3 4 5 6 7 8 9 10 20 16 18
输出样例 1:
30 11 2 9.7 9
输入样例 2:
8 1 2 4 5 6 7 9 16
输出样例 2:
N 11 2 N 9
//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 n1=0,n2=0,n3=0,n5=0;
double n4=0.0,sum4=0.0;
int i2=0,i4=0;
int[] num=new int[n];
for(int i=0;i<n;i++){
num[i]=in.nextInt();
if(num[i]%5==0&&num[i]%2==0){
n1+=num[i];
continue;
}
if(num[i]%5==1){
n2+=Math.pow(-1,i2)*num[i];
i2++;
continue;
}
if(num[i]%5==2){
n3++;
continue;
}
if(num[i]%5==3){
sum4+=num[i];
i4++;//记得求平均
continue;
}
if(num[i]%5==4){
if(num[i]>n5){
n5=num[i];
}
continue;
}
}
n4=sum4/i4;
if(n1!=0){
System.out.print(n1+" ");
}
else{
System.out.print("N ");
}
if(i2!=0){
System.out.print(n2+" ");
}
else{
System.out.print("N ");
}
if(n3!=0){
System.out.print(n3+" ");
}
else{
System.out.print("N ");
}
if(sum4!=0){
System.out.printf("%.1f ",n4);
}
else{
System.out.print("N ");
}
if(n5!=0){
System.out.print(n5);
}
else{
System.out.print("N");
}
}
}
Sylvia_Lyn
发布了8 篇原创文章 · 获赞 0 · 访问量 179
私信
关注