Home > Back-end >  C beginners small white help bosses! Add a variable how wrong???
C beginners small white help bosses! Add a variable how wrong???

Time:03-03

Recently I was followed a book - "informatics orsay a tong (c + + edition)" learning c + +, a one-dimensional array computer exercises in question is as follows:

[title description]
Output an integer sequence sum is not the same as the maximum number of digits,

[enter]
Input is divided into two lines:

The first behavior N (N is the number of the next few, N & lt;=100);

The second line of N integers, separated by a space between number and number, every integer range is 1000000 to 1000000,

[output]
Output for the N number removed the the sum of the rest of the number of large number,

[input sample]
3
1 2 3
[output sample]
3

My program is as follows:

 
# include & lt; Cstdio>
Int main ()
{
Int j, Max, min,
The scanf (" % d ", & amp; M);
Int Numbers [10001].
For (int I=1; I & lt;=m; + + I)
{
The scanf (" % d ", & amp; Numbers] [I - 1);
If (I==1)
{
Max=min=Numbers [0];
}
If (Numbers] [I - 1 & gt; Max)
{
Max=Numbers [I - 1);
}
If (Numbers [I - 1] {
Min=Numbers [I - 1);
}
}
Printf (" % d \ n ", (Max - min));
return 0;
}


The book has a matching evaluation website, http://ybt.ssoier.cn:8088/, I will give my application up, it USES 10 team tested 10 times, 4 times out of the question, it says wrong answer, I wonder   , the along while also didn't look out where is wrong, so I just look at the book reference answer, the answer is as follows:

 
# include
using namespace std;
Int main ()
{//Max initialized to very small number, can guarantee to replace the number in the array, the minimum value in the same way
Int a [10001], m, Max=- 10001, min=10001;
The scanf (" % d ", & amp; M);
for (int i=1; i<=m; + + I)
{
The scanf (" % d ", & amp; A [I]);
If (a [I] & gt; Max) Max=a [I];
If (a [I] }
Printf (" % d ", Max - min);
return 0;
}


I wonder the   , there is no difference algorithm ah??????

Later found: I created an integer variable difference, and the answer no, direct output Max - min, I remove the difference after the tests are passed, I was wondering, the Max - min into into the variable calls and direct use different again??????? Anyway is an integer, no type different problems, what is wrong???

O, give advice or comments!!!!!! Thank you!!!!!!

CodePudding user response:

Bosses for help all of you!!!!!! Crab crab, ladies and gentlemen!!!!

CodePudding user response:

[output]
Output for the N number removed the the sum of the rest of the number of large number,
There is no sum part your code?

CodePudding user response:

Not the same as the maximum number of digital sum
With
The smallest reduction of large number for
It is one thing?

CodePudding user response:

///title description 
//output an integer sequence sum is not the same as the maximum number of digits,
//
//[enter]
//input is divided into two lines:
//
//the first behavior N (N is the number of the next few, N & lt;=100);
//
//the second line of N integers, separated by a space between number and the number of every integer range is 1000000 to 1000000,
//

//(output)//output for the N number removed the the sum of the rest of the number of large number,
//
///input sample
//3
//1 2 3
///output sample
//3
# include
using namespace std;
Int main ()
{
Int I, a [100], m, Max=- 1000001, the sum;
The scanf (" % d ", & amp; M);
For (I=0; iThe scanf (" % d ", & amp; A [I]);
If (a [I] & gt; Max) Max=a [I];
}
Sum=0;
For (I=0; iIf (a [I]! Sum=Max) +=a [I];
}
Printf (" % d \ n ", sum);
return 0;
}
//enter
//4
//1 2 4 4
//output
//3
//

CodePudding user response:

I haven't see the title, the output output for the N number removed the the rest of the number of large number, the sum of the code is to find a number of minimum and maximum number, the difference between the output them?

CodePudding user response:

High school math teacher on the blackboard: "the topic! The topic! The topic!"
  • Related