There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.
Write a program which prints heights of the top three mountains in descending order.
Input
Height of mountain 1 Height of mountain 2 Height of mountain 3 . . Height of mountain 10
Constraints
0 ≤ height of mountain (integer) ≤ 10,000
Output
Height of the 1st mountain Height of the 2nd mountain Height of the 3rd mountain
Sample Input 1
1819 2003 876 2840 1723 1673 3776 2848 1592 922
Output for the Sample Input 1
3776 2848 2840
Sample Input 2
100 200 300 400 500 600 700 800 900 900
Output for the Sample Input 2
900 900 800
题解:排序一下即可;
代码(C语言)
#include <stdio.h>
#include <stdlib.h>
void paixu(int a[],int n)
{
int i,k,t;
for(i=1;i<n;i++){
t=a[i];k=i-1;
while(t>a[k]){
a[k+1]=a[k];k--;
if(k==-1)break;
}
a[k+1]=t;
}
}
int main()
{
int i,a[10];
for(i=0;i<10;i++)
scanf("%d",&a[i]);
paixu(a,10);
printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
return 0;
}