Home > Back-end >  Oj in the school system, always appear the Presentation Error, have know brother help a look
Oj in the school system, always appear the Presentation Error, have know brother help a look

Time:01-21


 
#include
# include

Int main ()
{
Int n, j=1;
Int Max, min, temp.
The scanf (" % d ", & amp; n);
Int * a=(int *) malloc (sizeof (int) * n);
For (int I=0; I & lt; n; I++) {
The scanf (" % d ", & amp; A [I]);
}
Min=Max=0;
While (j & lt; N) {
If (a [j] & gt; A (Max))
Max=j;
If (a [j] Min=j;
j++;
}
Temp=a, [0].
A [0]=a/min;
A (min)=temp;
Temp=a [n - 1);
A [n - 1)=a (Max);
A (Max)=temp;

For (int I=0; I & lt; N - 1; I++)//then with modified with the output, but the results do wrong answer, I really took
Printf (" % d ", a [I]);
Printf (" % d ", a [n - 1));

printf("\n");//this line to distinguish a result, the time is not easy to distinguish, upload code

For (int I=0; I & lt; N; I++)//use this output is PE error, I would like to roughly the reason is that there is space behind the last element
Printf (" % d ", a [I]);
return 0;
}


CodePudding user response:

Code is no problem, pay attention to in the last add free (a);//release space

Trouble spots may be your compiler compiler or server is the C language, like the for (int I=0; I & lt; N - 1; I++) that define a local variable in a for loop, general C compilers do not support, is one of the characteristics of C + +,

In view of the above have defined the j, the back of the loop can be used as a loop variable, j

CodePudding user response:

The final output modify try:
 for (int I=0; I & lt; n; I++) 
Printf (" % d % c, "a [I], (i

CodePudding user response:

Above the z more, modify:
 for (int I=0; I & lt; n; I++) 
Printf (" % d % c, "a [I], (i

CodePudding user response:

The
reference 1/f, confident boy reply:
code is no problem, pay attention to in the last add free (a);//release space

Trouble spots may be your compiler compiler or server is the C language, like the for (int I=0; I & lt; N - 1; I++) that define a local variable in a for loop, general C compilers do not support, is one of the characteristics of C + +,

In view of the above have defined the j, the back of the loop can be used as a loop variable, j
no elder brother! Or Wrong Answer
 # include & lt; Stdio. H> 
# include

Int main ()
{
Int n, j=1;
Int Max, min, temp.
The scanf (" % d ", & amp; n);
Int * a=(int *) malloc (sizeof (int) * n);
For (int I=0; I & lt; n; I++) {
The scanf (" % d ", & amp; A [I]);
}
Min=Max=0;
While (j & lt; N) {
If (a [j] & gt; A (Max))
Max=j;
If (a [j]
Min=j;
j++;
}
Temp=a, [0].
A [0]=a/min;
A (min)=temp;
Temp=a [n - 1);
A [n - 1)=a (Max);
A (Max)=temp;
For (j=0; JPrintf (" % d ", a [j]);
Printf (" % d \ n ", a [n - 1));//here/n I add don't add also by not
Free (a);
return 0;
}

CodePudding user response:

reference QZJHJXJ reply: 3/f
above the z, modify:
 for (int I=0; I & lt; n; I++) 
Printf (" % d % c, "a [I], (i
or not, by no, I'm going to throw up

CodePudding user response:

Such a change, try again:
 # include & lt; Stdio. H> 
# include

Int main ()
{
Int n, j;
Int Max, min, temp.
The scanf (" % d ", & amp; n);
Int * a=(int *) malloc (sizeof (int) * n);
For (j=0; J & lt; n; J++) {
The scanf (" % d ", & amp; A [j]);
}
Min=Max=0;
J=1;
While (j & lt; N) {
If (a [j] & gt; A (Max))
Max=j;
If (a [j]
Min=j;
j++;
}
Temp=a, [0].
A [0]=a/min;
A (min)=temp;
Temp=a [n - 1);
A [n - 1)=a (Max);
A (Max)=temp;

For (j=0; J & lt; N; J++) {
If (j==0)
Printf (" % d ", a [j]);
The else printf (" % d ", a [j]);
}
Free (a);
return 0;
}

CodePudding user response:

 # include & lt; Stdio. H> 
# include

Int main ()
{
Int n, j=1;
Int Max, min, temp.
Int * a=NULL;

The scanf (" % d ", & amp; n);
//int * a=(int *) malloc (sizeof (int) * n);
A=(int *) malloc (sizeof (int) * n);
For (int I=0; I & lt; n; I++) {
The scanf (" % d ", & amp; A [I]);
}
Min=Max=0;
While (j & lt; N) {
If (a [j] & gt; A (Max))
Max=j;
If (a [j]
Min=j;
j++;
}
Temp=a, [0].
A [0]=a/min;
A (min)=temp;
Temp=a [n - 1);
A [n - 1)=a (Max);
A (Max)=temp;
For (j=0; JPrintf (" % d ", a [j]);
Printf (" % d \ n ", a [n - 1));//here/n I add don't add also by not
Free (a);
return 0;
}

Try again, doubt you submit server compilation problems, compiled by;

CodePudding user response:

refer to 6th floor QZJHJXJ response:
this modification, and try again:
 # include & lt; Stdio. H> 
# include

Int main ()
{
Int n, j;
Int Max, min, temp.
The scanf (" % d ", & amp; n);
Int * a=(int *) malloc (sizeof (int) * n);
For (j=0; J & lt; n; J++) {
The scanf (" % d ", & amp; A [j]);
}
Min=Max=0;
J=1;
While (j & lt; N) {
If (a [j] & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related