标签:include product 函数 scanf print oid def sort for
//最大的算式 //对输入的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; }
标签:include product 函数 scanf print oid def sort for
原文地址:https://www.cnblogs.com/Hqx-curiosity/p/12238198.html