One day two pat (4) 1012

Today brush to 1012, and this problem is he just really do make life difficult test points 7-8. Finally do come out,

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 more than the number of the other the number 2;
  • A . 4 = 5 Mean is other than 3 after the numbers to the nearest decimal place;
  • A 5 = more than the maximum number of the number 4 after 5 addition.

Input formats:

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 formats:

For a given N positive integers, 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.

Sample Input 1:

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

Output Sample 1:

30 11 2 9.7 9

Sample Input 2:

8 1 2 4 5 6 7 9 16

Output Sample 2:

N 11 2 N 9

#include<iostream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main ()
{
int n;
int a0=0,a1=0,a2=0,a3=0,a4=0,k;
int count[5]={0};
cin>>n;
for(int i=0;i<n;i++)
{
cin>>k;
if(k%5==0&&k%2==0)
{
a0+=k;
count[0]++;
}
else if(k%5==1)
{
if(count[1]%2==0)
{
a1+=k;
}
else
{
a1-=k;
}
count[1]++;
}
else if(k%5==2)
{
a2++;
count[2]++;
}
else if(k%5==3)
{
a3+=k;
count[3]++;
}
else if(k%5==4)
{
if(k>a4)
{
a4 = k;
}
count[4]++;
}
}
if(count[0]!=0)
{
cout<<a0<<" ";
}
else
{
cout<<"N"<<" ";
}
if(count[1]!=0)
{
cout<<a1<<" ";
}
else
{
cout<<"N"<<" ";
}
if(count[2]!=0)
{
cout<<a2<<" ";
}
else
{
cout<<"N"<<" ";
}
if(count[3]!=0)
{
//printf("%.1f ", (double)a3/ count[3]);
cout<<fixed<<setprecision(1)<<(double)a3/count[3]<<" ";
}
else
{
cout<<"N"<<" ";
}
if(count[4]!=0)
{
cout<<a4;
}
else
{
cout<<"N";
}
}
Test point 7 is retained because c ++ floating-point control to use fixed decimal, setprecision control digits.
8 test point because of self-imposed time possible plus and minus offset reference online last brother, and finally change right. . . .

Guess you like

Origin www.cnblogs.com/guairenkuangren/p/12093308.html