0
I was writing a code and I stagnated on some problem along the way. Follow below for more details:
Enunciation
Afonso is in line to buy tickets to his concert favorite band. Afonso is at the end of the line, so the time of waiting seems endless. To pass the time, Afonso decided count the people who meet in front of you, there is exactly N people. Additionally, Afonso noted the height of each person, by order from the first of the row to the last. It is known that a person can see the box office if there’s no one in front of you with the same height or higher. Given the list of heights N persons in the queue at front of Afonso, in order from the first of the row to the last (which is immediately in front of Afonso) you can count how many people can see the box office?
Given the number of people N in the row and the height of each in order, calculate the number of people who can see the box office.
Input
An integer N on a line, the number of people in line. The next row has whole N, the heights of the people in order of position in the queue, i.e., the first integer is the height of the first person in the queue.
Output
An integer in a row, corresponding to the number of people who can see the box office, followed by a line change.
Restrictions
The following limits are guaranteed in all test cases that will be placed on the programme:
- 1 N 100 Number of persons
- 1 Ai 1,000 Height of each person
Example 1
5
170 153 170 180 175
2
Only two people can see the box office, the first person, height 170 and the fourth, height 180.
Example 2
7
10 120 30 135 11 2 186
4
The Doubt
In an attempt to solve this problem, I wrote the following code:
#include <iostream>
using namespace std;
int array[101];
int main()
{
int x;
cin >> x;
for(int i = 0; i < x; i++) {
cin >> array[i];
}
int sum;
for(int i = 0; i < x - 1; i++) {
if(array[i] < array[i + 1]) {
sum += 1;
}
}
cout << sum << endl;
return 0;
}
And so if anyone could tell me what’s wrong, I’d really appreciate it. Cumps.