1, the input number N;
2, the output n number of n
Solution, and N number first, and the N number of sorting, from big to small, in turn, additive, until meet the conditions of output N number, but a lot of problems in the process, ask Daniel taught, can you help provide code
CodePudding user response:
Is that right# include & lt; Bits/stdc++. H>
using namespace std;
E5 const int maxn=2 + 5;
Const int inf=0 x3f3f3f3f;
Int a [maxn];
Int main ()
{
Int n, sum=0, all=0;
Cin> n;
for(int i=1; i<=n; + + I) cin> A, [I].
for(int i=1; i<=n; + + I) all +=a, [I].
Sort (a + 1, a + n + 1);
Int now=n;
While (now>=1 & amp; & The sum * 10 & lt;=all * 8) {//sum<=all * 0.8
Cout
-- now;
}
For (int I=n; i> Now; - I) {
Cout}
Cout
}
CodePudding user response:
# include & lt; iostream># include & lt; Algorithm>
# include & lt; Cmath>
using namespace std;
Bool CMP (int a, int b)
{
Return a & gt; b;
}
Int main ()
{
int num;
Float arr [20]={0.0};
Float sum=0;
Cout & lt; <"Input the number of input:";
Cin & gt;> Num.
For (int I=0; i
Cin & gt;> Arr [I];
The sum +=arr [I];
}
Sort (arr, arr + num, CMP);
Float temp=arr [0];
int i=0;
While (temp<=sum * 0.8)
{
Cout & lt;
Temp +=arr [I];
}
Cout & lt;
return 0;
}