Aizu Judge 0001 List of Top 3 Hills
問題
入力値を降順ソートすればよい.
入力例
1819
2003
876
2840
1723
1673
3776
2848
1592
922
出力例
3776
2848
2840
C
#include<stdlib.h> #include<stdio.h> int compare(const void* s,const void *t ){ return (*((int*)t) - *((int*)s)); } int main(){ int height[10]; int i=0; while(~scanf("%d",&height[i++])); qsort(height, 10, sizeof(height[0]), compare ); for( i = 0; i < 3 ; i++ ) printf("%d\n",height[i]); return 0; }
# include <iostream> # include <algorithm> using namespace std; int main() { int h[10]; for(int i=0;i<10;i++)cin >> h[i]; sort(h,h+10); reverse(h,h+10); for(int i=0;i<3;i++)cout << h[i] << endl; return 0; }
#include<iostream> #include<algorithm> int main(){ int i=0,h[10]; while(std::cin>>h[i++]); std::sort(h,h+10); for(i=9;i>6;)std::cout<<h[i--]<<"\n"; }
import java.util.*; class Aizu{ public static void main(String[] args){ int height[] = new int[10]; Scanner scan = new Scanner(System.in); for(int i=0;i<10;i++){ height[i] = scan.nextInt(); } Arrays.sort(height); for(int i=9;i>9-3;i--){ System.out.println(height[i]); } } }
height = [int(raw_input()) for i in range(10)] for i in sorted(height,reverse=True)[:3]: print i
height = [] 10.times{height.push(gets.to_i)} puts height.sort{|i,j| j<=>i}[0,3]
puts ([0]*10).map{gets.to_i}.sort{|i,j| j<=>i}[0,3]
<?php $height = array(); for($i=0;$i<10;$i++){ array_push($height,(int)fgets(STDIN)); } rsort($height); for($i=0;$i<3;$i++){ echo $height[$i]."\n"; } ?>