输入一个正整数repeat (0输入一个正整数n (1例:括号内是说明
输入
3   (repeat=3)
4 5 1 7 6
3 1 2 3
5 5 4 3 2 1
输出
7 6 5 1
3 2 1
5 4 3 2 1

#include <stdio.h>
int main( )
{
  int ri, repeat;
  int i, index, k, n, temp;
  int a[10];

  scanf("%d", &repeat);
  for(ri=1; ri<=repeat; ri++){
     scanf("%d", &n);
     for(i=0; i<n; i++)
        scanf("%d", &a[i]);
    for(k=0; k<n; k++){
      index=k;
      for(i=k+1;i<n;i++)
        if(a[i]>a[index])
          index=i;
      temp=a[index];
      a[index]=a[k];
      a[k]=temp;
    }
     for(i=0; i<n; i++)
        printf("%d ", a[i]);
     printf("\n");
  }
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(508)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember