PAT B Zhenti 1002. Digital Category

PAT B Zhenti 1002. Digital Category

Title Description

Given to a series of positive integers, press the demand for digital classification, and outputs the following five numbers:

A1 = 5 can be divisible numbers and even numbers;
A2 = 1 is more than the digital sum interleaved in the order given, i.e. after 5 calculates inter-N2 + N3-N1 ... N4;
A3 is = 5 in addition to the number of more than 2 after the digital;
; A4 = 1 is the average of 5 other than the number 3, decimal place
A5 = 5 digital I 4 is the maximum number other.

Input Format

Each input comprises a test. Each test case is given a first positive integer of not more than 1000 N, and then gives the N does not exceed 1000 to be classified positive integer. Between numbers separated by a space.

Output Format

For a given positive integer N, is calculated according to A1 ~ A5 subject of the request and sequentially outputting in a row. Between numbers separated by spaces, but the end of the line may not have the extra space.
If a certain type wherein the number does not exist, the output "N" in the corresponding position.

SAMPLE INPUT

13 1 2 3 4 5 6 7 8 9 10 20 16 18

Sample Output

30 11 2 9.7 9

Topic ideas

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+10;
int q[N];

int main(){
    double a4 = 0.0;
    int a1=0,a2=0,a3=0,a5=0,count=0;
    int zed = 1;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&q[i]);
    for(int i=0;i<n;i++){
        if(q[i]%5==0&&q[i]%2==0){
            a1+=q[i];
        }else if(q[i]%5==1){
            a2 += zed*q[i];
            zed = -zed;
        }else if(q[i]%5==2){
            a3++;
        }else if(q[i]%5==3){
            a4+=q[i];
            count++;
        }else if(q[i]%5==4){
            if(q[i]>a5){
                a5 = q[i];
            }
        }
    }
    if(a1!=0)printf("%d ",a1);
    else printf("N ");
    if(a2!=0)printf("%d ",a2);
    else printf("N ");
    if(a3!=0)printf("%d ",a3);
    else printf("N ");
    if(count!=0){
        double a = a4/count;
        printf("%.1f ",a);
    }else printf("N ");
    if(a5!=0)printf("%d",a5);
    else printf("N");
    
    return 0;
}

Guess you like

Origin www.cnblogs.com/fsh001/p/12186579.html