Use namespace std
int main()
{
int s,n,a[ 100],b[ 100],temp,temp 2;
Cout & lt& lt "Please enter the number of integers in this string"
CIN & gt; & gtn;
Cout & lt& lt "Please enter various integers"
for(int I = 1; I < = n; i++)
{
CIN & gt; & gta[I];
}
Cout & lt& lt "Please enter an integer to compare"
CIN & gt; & gts;
for(int j = 1; j & lt= n; j++)
{
b[j]= ABS(s-a[j]); //Calculate the absolute difference between integer columns and items.
}
b[0]= a[0]= 0;
temp = 0;
temp 2 = 0;
for(int g = 1; g & lt= n; G++)// Make some judgments.
{
for(int f = 1; f & lt= n-f; F++)// Where to exchange?
{
if(b[f]& lt; =b[f- 1])
{
temp = b[f]; //Use bubble sorting to sort the absolute difference.
b[f]= b[f- 1];
b[f- 1]= temp;
temp 2 = a[f];
a[f]= a[f- 1];
a[f- 1]= temp 2; //Sort the corresponding integer columns to achieve the purpose.
}
}
}
for(int m = 1; m & lt= n; m++)
{
cout & lt& lta[m]& lt; & lt" ";
}
Returns 0;
}
This question is written in vc++6.0. After debugging, it can be run. In the loop of the above problems, the algorithm may be redundant. Please understand the optimization yourself. There are detailed instructions in the program, so the flow chart is not attached.