View Code of Problem 61

#include<stdio.h>
int main(){
    int t,n;
    int a[100];
    scanf("%d",&t);
    int i;
    while(t--){
        scanf("%d",&n);
        int j,temp;
        for(j=0;j<n;j++)
            scanf("%d",&a[j]);
        //冒牌排序,使序列由小到大;
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                if(a[i]>a[j]){
                    temp = a[j];
                    a[j]=a[i];
                    a[i]=temp;
                }

            }
        }
        int max=0,sum=0;
        for(i=0;i<n;i++){
            sum=a[i]*(n-i);
            if(sum>max)
                max=sum;
        }
        printf("%d\n",max);
    }
}

Double click to view unformatted code.


Back to problem 61