A pair of x values in the string on a card is a y number that is part of the same string and has the following property:
- if x is in an even position, y is the minimum of numbers greater than x that are to the left of x in a vector
-if x is in odd position, y is the minimum of numbers greater than x that are to the right of x in a vector
The program will display on the screen a string of n numbers, representing the string of pairs corresponding to each x element in the string. If there is a number x that is not such a pair in the string, the value -1 will be displayed instead of its pair.
0 < n ≤ 100
0 ≤ x ≤ 1000
#include <iostream>
usingnamespace std;
int main() {
int n, i, v[102];
cin >> n;
for (i = 1; i <= n; i++) {
cin >> v[i];
}
// for (i = 1; i <=n; i++) {
if (i % 2 == 0) {
}
if (i % 2 == 1) {
}
return 0;
}
#include <iostream>
usingnamespace std;
int search( int A[], int value, int first, int last )
{
bool found = false;
int mn = -1;
for ( int i = first; i <= last; i++ )
{
if ( A[i] > value )
{
if ( !found ) mn = A[i];
elseif ( A[i] < mn ) mn = A[i];
found = true;
}
}
return mn;
}
int main()
{
constint SIZE = 1000;
int v[SIZE], n;
cin >> n;
for ( int i = 0; i < n; i++ ) cin >> v[i];
for ( int i = 0; i < n; i++ )
{
if ( i % 2 ) cout << search( v, v[i], 0 , i - 1 ) << ' '; // Ahem, EVEN in OP's notation!!!
else cout << search( v, v[i], i + 1, n - 1 ) << ' ';
}
}