write a code that first gets n.then gets n numbers(solider's height),(numbers will separate with space)and prints out the number of soldiers that are between the smallest and the tallest soldiers.note that n<10000 and if the tallest one is in front of the smallest should print 0.
input 1:
5
100,102,120,300,500
output 1:
3
input 2:
7
100 90 40 80 10 30 20
output 2:
0
The problem states that the input heights are separated by spaces, but your input shows them separated by a comma. Make sure that you use spaces when creating the input.
1 2
cin >> n;
inta[n], num, maxim = 0, minim = 0;
The underlined part is non-standard C++. You could create a vector instead. Better yet, figure out how to do the problem without storing all the numbers at all.
1 2 3 4 5 6 7
cin >> s;
for (int j = 0; j < n; j++) {
num += (s[i] - 48);
num *= 10;
}
a[i] = num;
s = "";
You can replace all of this with cin >> a[i] Once that's done, s and num are no longer used so they can be removed.
The output isn't quite right. I suggest you temporarily add cout << "minim=" << minim << ", Maxim=" << maxim << '\n'; just before generating the output.