Home > Back-end >  Help bosses a pta, small L problem
Help bosses a pta, small L problem

Time:10-19


I bad code
#include
#include
#include
using namespace std;
//int the factorial (int a) factorial function
{
Int b=1;
If (a==1 | | a==0)
Return b;
if(a>
=2){
B=a * factorial (a - 1);
Return b;
}
If (a<0)
return 1;
}
Int cn (int n, int k)//combinations of function
{
The return of the factorial (n)/(the factorial (k) * factorial (n - k));
}
Int main ()
{
Int n, I=0, I, xb=0;
cin> & gt; n;
Int a [n].
Int Cna=cn (n, 2);//calculate all possible
Int b (Cna);//use an array to undertake all possible difference
for(i=0; i{
cin> & gt; A, [I].
}
for(i=0; i{
For (I=I + 1; I{
B/xb=abs (a [I] - [I] a);

Xb++;
}

}
Sort (b, b + Cna);//fast row
coutreturn 0;
}

Is floating point error will be displayed after running but the answer is correct, and bosses,

CodePudding user response:

The factorial has a problem, will exceed the scope of the int
In fact it is not necessary to use array, as long as the two variables, a record minimum difference, a record second uninteresting facts value is ok, so it is not necessary to calculate the factorial
  • Related