CCF CSP certification solutions in March 2019

The first question: 201903-1


[Subject Background]

In data analysis, the minimum and maximum values ​​and the median are commonly used statistical information.
[Title description] The
teacher gave you the measurement data composed of n integers, to ensure order (may be ascending or descending), there may be duplicate data. Please count the maximum value, median value and minimum value in this set of measurement data, and output these three numbers in descending order.
[Input format]
Read data from standard input.
The first line input-an integer n, there are n ordered integers in the second line, indicating the measurement data, may be arranged in ascending or descending order, there may be multiple consecutive integers equal, integers and integers are separated by spaces .
[Output format]
Output to standard output.
Contains-lines, including the maximum, median, and minimum three numbers, and output in descending order. Use spaces to separate data. For integers, please directly output integers, for possible fractions, please output the result of rounding to 1 decimal.
[Sample 1 input]
3
-124
[Sample 1 output]
42-1
[Explanation of sample 1]
4 is the maximum value, 2 is the median, and -1 is the minimum value.
[Sample 2 input]
4
-2 -13 4


#include<stdio.h>
int a[100010];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int maxn,minn;
	
	if(a[0]>a[n-1]){
		maxn=a[0],minn=a[n-1];
		if(n%2==1){
			printf("%d %d %d\n",maxn,a[n/2],minn);
		}
		else {
			if((a[n/2]+a[n/2-1])%2==1)	printf("%d %.1f %d\n",maxn,(double)(a[n/2]+a[n/2-1])/2,minn);
			else printf("%d %d %d\n",maxn,(a[n/2]+a[n/2-1])/2,minn);			
		}

	} 
	else {
		maxn=a[n-1],minn=a[0];
		if(n%2==1){
			printf("%d %d %d\n",maxn,a[n/2],minn);
		}
		else{
			if((a[n/2]+a[n/2-1])%2==1)	printf("%d %.1f %d\n",maxn,(double)(a[n/2]+a[n/2-1])/2,minn);
			else printf("%d %d %d\n",maxn,(a[n/2]+a[n/2-1])/2,minn);	
		}
	}


	return 0;
}

 

The second question:

 

Published 108 original articles · praised 48 · 50,000+ views

Guess you like

Origin blog.csdn.net/larry1648637120/article/details/90085500
Recommended