PAT B digital examination of the 1012 classification
topic:
Given to a series of positive integers, press the demand for digital classification, and outputs the following five numbers:
A
1
= 5 be divisible numbers and even numbers;
A
2
= 5 is more than 1 after the digital addition is performed in the order given staggered sum, i.e. calculating n-
1
- n-
2
+ n-
3
-n
. 4
⋯;
a
3
= 5 is other than the number of the number 2;
a
. 4
= I 3 is the addition of 5 averages, one decimal place;
a
5
= I 5 is the maximum digital number 4 after the addition.
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 A
. 1
~ A
. 5
and the output order 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 in the corresponding position N.
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
Code:
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include <memory.h>
#include <math.h>
int z = 0, x = 0, p = 0, c = 0, b = 0;
int z1 = 0, p1 = 0, c1 = 0, b1 = 0;
float v = 0.0, n = 0.0;
void A_1(int a)
{
if (a % 5 == 0 && a % 2 == 0)
{
z1 = 1;
z = z + a;
}
}
void A_2(int a)
{
if (a % 5 == 1)
{
p1 = 1;
if (x == 0)
{
p = p + a;
x = 1;
}
else
{
p = p - a;
x = 0;
}
}
}
void A_3(int a)
{
if (a % 5 == 2)
{
c1 = 1;
c++;
}
}
void A_4(int a)
{
if (a % 5 == 3)
{
v = v + a;
n++;
}
}
void A_5(int a)
{
if (a % 5 == 4)
{
b1 = 1;
if (a > b)
{
b = a;
}
}
}
int main(void)
{
int a = 0, i = 0, k = 0, j = 0;
int N = 0;
float q=0.0;
scanf("%d", &N);
for (i = 0; i < N; i++)
{
scanf("%d", &a);
A_1(a);
A_2(a);
A_3(a);
A_4(a);
A_5(a);
}
if (z1 != 0)
{
printf("%d ", z);
}
if (z1 == 0)
{
printf("N ");
}
if (p1 != 0)
{
printf("%d ", p);
}
if (p1 == 0)
{
printf("N ");
}
if (c1 != 0)
{
printf("%d ", c);
}
if (c1 == 0)
{
printf("N ");
}
if (n != 0)
{
q = v / n;
printf("%.1f ", q);
}
if (n == 0)
{
printf("N ");
}
if (b1 != 0)
{
printf("%d", b);
}
if (b1 == 0)
{
printf("N");
}
// array = (int*)malloc(n * (sizeof(int)));
// free(array);
return 0;
}
This question can not be determined whether the output 0 N, a flag may be defined by a single result.