算法训练——最大的算式
//最大的算式 //对输入的N个数逆序排序,前K个数的积乘于剩余N-K个数的和 #include<stdio.h> #include<stdlib.h> #define MAXN 100 int comp(const void*a,const void*b)//用来做比较的函数。 { return *(int*)b - *(int*)a; //降序 } int main(){ int i,N,K,sum = 0,product = 1; int a[MAXN]; scanf("%d %d",&N,&K); for(i=0;i<N;i++) scanf("%d",&a[i]); qsort(a,N,sizeof(int),comp); for(i=0;i<K;i++) product *=a[i]; for(i=K;i<N;i++) sum += a[i]; printf("%d",sum*product); return 0; }
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23