pat-B1012- digital classification

Topic Link -> Link

Thinking

  1. In accordance with the meaning of the questions to enumerate all cases, pay attention to the output format, output can not be the last case back with spaces.

Code

ps. still ugly ...

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>

using namespace std;
const int maxn=1000;
int a[maxn]={0};

int main(){
    int n,i,sum1,sum2,flag,count,max;
    double sum3;
    while(scanf("%d",&n)!=EOF){
        sum1=0;
        sum2=0;
        flag=1;
        count=0;
        sum3=0;
        max=-1;
        int none[5]={0};
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
            if(a[i]%5==0&&a[i]%2==0){//case1
                sum1+=a[i];
                none[0]++;
            }
            else if(a[i]%5==1){//case2
                sum2+=(pow(-1,(flag+1))*a[i]);
                flag++;
                none[1]++;
            }
            else if(a[i]%5==2){//case3
                count++;
                none[2]++;
            }
            else if(a[i]%5==3){//case4
                sum3+=a[i];
                none[3]++;
            }
            else if(a[i]%5==4){//case5
                none[4]++;
                if(a[i]>max)max=a[i];
            }
            else continue;
        }//for1
        for(i=0;i<5;i++){
            if(none[i]==0){
                if(i!=4){
                    printf("N ");
                }
                else printf("N\n");
            }
            else if(i==0){
                printf("%d ",sum1);
            }
            else if(i==1){
                printf("%d ",sum2);
            }
            else if(i==2){
                printf("%d ",count);
            }
            else if(i==3){
                printf("%.1f ",sum3/none[3]);
            }
            else if(i==4){
                printf("%d",max);
            }
        }//for2
    }//while
    return 0;
}
Released eight original articles · won praise 1 · views 126

Guess you like

Origin blog.csdn.net/MichealWu98/article/details/104010000