PAT乙级

pat1012

2018-09-24  本文已影响0人  hsinsDfy
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){
    int A1=0,A2=0,A3=0,A5=0;
    float A4=0;
    int m=1,cntA4=0;
    int flag=0;//判断有没有A2,一定要注意!!!
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        int j;
        cin>>j;
    if(j%5==0&&j%2==0)
        A1+=j;
    else if(j%5==1){
        flag=1;
        A2=A2+j*m;
        m=m*(-1);
    }
    else if(j%5==2)
        ++A3;
    else if(j%5==3){
        A4+=j;
        ++cntA4;
    }
    else if(j%5==4)
        if(A5<j)
            A5=j;
    }
    if (A1!=0)
    cout<<A1<<" ";
    else
        cout<<"N ";
    if (flag!=0)
    cout<<A2<<" ";
    else
        cout<<"N ";
    if (A3!=0)
    cout<<A3<<" ";
    else
        cout<<"N ";
    if (A4!=0){
        A4=A4/cntA4;
    cout<< setiosflags(ios::fixed)<< setprecision(1)<<A4<<" ";
    }
    else
        cout<<"N ";
    if (A5!=0)
    cout<<A5;
    else
        cout<<"N";
    system("pause");
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读