Given a positive integer number, press the classification requirements for digital, and outputs the following five figures:
A1 = 5 be divisible by numbers in all of the even and;
A2 = 1 is more than the numbers given in addition after 5 interleaved sequence summing, i.e. calculate + N3-N2-N1 ... N4;
A3 = the number is more than 5 after the other the number 2;
A4 = 5 by addition of more than 3 after the average number, 1 decimal place bit;
A5 = 5 remainders after division by numbers 4, the maximum number.
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:
a given positive integer N, is calculated by the subject of the request and sequentially outputs A1 ~ A5 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.
Input Example 1:
1,312,345,678,910,201,618
Output Sample 1:
30 112 9.7 9
Input Sample 2:
8124567916
Output Sample 2:
N. 11 2 N 9
#include <stdio.h>
int main() {
int num[1000], N, a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, flag = 1, numa4 = 0, count[5] = {0};
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &num[i]);
}
for (int i = 0; i < N; i++) {
if (num[i] % 5 == 0 && num[i] % 2 == 0) {
a1 = a1 + num[i];
count[0] = a1;
}
if (num[i] % 5 == 1) {
a2 = a2 + flag * num[i];
flag = -1 * flag;
count[1] = a2;
}
if (num[i] % 5 == 2) {
a3++;
count[2] = a3;
}
if (num[i] % 5 == 3) {
numa4++;
a4 = a4 + num[i];
count[3] = a4;
}
if (num[i] % 5 == 4) {
if (num[i] > a5) {
a5 = num[i];
count[4] = a5;
}
}
}
if (count[0] == 0) {
printf("N ");
} else printf("%d ", count[0]);
if (count[1] == 0) {
printf(" N");
} else printf("%d ", count[1]);
if (count[2] == 0) {
printf("N ");
} else printf("%d ", count[2]);
if (count[3] == 0) {
printf("N ");
} else printf("%.1f ", count[3] / (numa4 * 1.0));
if (count[4] == 0) {
printf("N");
} else printf("%d", count[4]);
}
//8 1 2 4 5 6 7 9 16
//13 1 2 3 4 5 6 7 8 9 10 20 16 18
Test Results: