中譯
#include "stdio.h" int quicksort(int p[],int left,int right) { if( left >= right ) return 0; int i,j,s,tmp; s = p[left]; i = left + 1; j = right; while( 1 ) { while( i < right && p[i] >= s ) i++; while( j > left && p[j] <= s ) j--; if( i >= j ) break; tmp = p[i]; p[i] = p[j]; p[j] = tmp; } tmp = p[left]; p[left] = p[j]; p[j] = tmp; quicksort(p,left,j - 1); quicksort(p,j + 1,right); return 0; } int main() { int num; scanf(" %d",&num); while( num-- ) { int i,j,n,p[20000]={0},save = 0,tmp; scanf(" %d",&n); for(i = 0;i < n;i++) { scanf(" %d",&p[i]); } quicksort(p,0,n - 1); for(i = 2;i < n;i+=3) { save += p[i]; } printf("%d\n",save); } return 0; }
沒有留言:
張貼留言