以下為通過高中生程式解題系統 AC (Accepted) 的 C 語言程式參考解答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <stdio.h> #include <stdlib.h> int main() { int p,tmp; int hs = -1; int ls = -1; char s[20]; while(scanf("%d",&p)!=EOF){ for( int i = 0 ; i < p ; i++){ scanf("%d",&s[i]); } for (int i = 0 ; i < p ; i++){ for (int j = i+1 ; j < p ; j++){ if( s[i] > s[j] ){ tmp = s[i]; s[i] = s[j]; s[j] = tmp ; } } } for (int i=0 ; i < p ; i++){ printf("%d",s[i]); if(i<p-1){ printf(" "); } } printf("\n"); for (int i=0 ; i < p ; i++){ if(s[i]<60){ hs = s[i] ; } } if(hs == -1){ printf("best case\n"); }else{ printf("%d\n",hs); } for (int i = p-1 ; i>=0 ; i--){ if(s[i]>=60){ ls = s[i]; } } if(ls == -1){ printf("worst case\n"); }else{ printf("%d\n",ls); } hs = -1; ls = -1; } return 0; } |
沒有留言:
張貼留言