Lanqiao Cup Score Statistics --- Recursion

Question 1500: [Blue Bridge Cup] [Algorithm Improved VIP] Time Limit for Score Statistics: 1Sec Memory Limit: 128MB Submitted: 1541 Solved: 727
Question Description
Given a percentile score T, divide it into one of the following five levels:

90 100 is A, 80 89 is B, 70 79 is C, 60 69 is D, 0~59 is E

There are several hundred-point scores (the number of scores does not exceed 1000). Please count the number of people in the five levels, and find the level with the largest number of people, and output the scores of all people in this segment in descending order ( There is only one level with the largest number of guarantees).
Input the
first line is the number of results n

The second line is the student's grades, a number of positive integers ranging from 0 to 100, separated by spaces.
Output The
first line is 5 positive integers, representing the number of students in the five levels of A, B, C, D, and E.

A positive integer in the second line indicates the number of people in the rank with the largest number of people

On the next line, several positive integers separated by spaces represent the scores of all people in the level with the largest number of people, and output them in descending order.

                样例输入
 10

100 80 85 77 55 61 82 90 71 60

                样例输出
                2 3 2 2 1

3
85 82 80

#include<stdio.h>
#include<math.h>
#include<string.h>

  int xb(int a,int b,int c,int d,int e)
  {
    
    
  	int max=e;
  	if(a>max) max=a;
  	if(b>max) max=b;
  	if(c>max) max=c;
  	if(d>max) max=d;
  	return max;
  }
  
  void shuchu(int *sre,int cns)
  {
    
    
  	for(int i=0;i<cns;i++)
  	{
    
    
  		for(int j=i+1;j<cns;j++)
  		{
    
    
  			if(sre[i]<sre[j]){
    
    
  				int t=sre[i];
  				sre[i]=sre[j];
  				sre[j]=t;
			  }
		  }
		  printf("%d ",sre[i]);
	  }
  }
  
  int main()
  {
    
    
  	int n;
  	int str[1001]={
    
    0};
  	scanf("%d",&n);
  	int a,b,c,d,e;
  	a=b=c=d=e=0;
	for(int i=1;i<=n;i++)
  	scanf("%d",&str[i]);
  	int sa[1000]={
    
    0},sb[1000]={
    
    0},sc[1000]={
    
    0},sd[1000]={
    
    0},se[1000]={
    
    0};
  	for(int i=1;i<=n;i++)
	  {
    
    
	  	switch(str[i]/10)
	  	{
    
    
	  		case 10:
	  		case 9:sa[a++]=str[i];break;
	  		case 8:sb[b++]=str[i];break;
	  		case 7:sc[c++]=str[i];break;
	  		case 6:sd[d++]=str[i];break;
	  		default:se[e++]=str[i];break;
		  }	  	
	}	
  		printf("%d %d %d %d %d\n",a,b,c,d,e);
 	int zd=0;
  	zd=xb(a,b,c,d,e);
  	printf("%d\n",zd);

	  if(zd==a) shuchu(sa,a);
	  else if(zd==b) shuchu(sb,b);
	  else if(zd==c) shuchu(sc,c);
	  else if(zd==d) shuchu(sd,d);
	  else shuchu(se,e);

  	return 0;
   }

Guess you like

Origin blog.csdn.net/qq_46232829/article/details/107615415