The exercise is this:
Assigned two vectors (V1 and V2) of integers. Check if within one of the two vectors (VY) there is a sequence of values in consecutive positions such that every element is included between two successive elements of a sequence of elements of the other vector (VX):
VX [i] < VY [j] < VX [i + 1] and VX [i + 1] < VY [j + 1] < VX [i + 2]
Note that, the relationship in order to exist, the sequence of elements VY must have at least two elements and the sequence of elements VX must contain double elements of VY. If the check is positive, generate and print the vector obtained by melting the two successions respecting the found relation:
..., VX [i], VY [j], VX [i + 1], VY [j + 1], VX [i + 2], ...
I don't want you to write the code of this exercise. I just want to be "guided" through every point of the exercise, like:
"First do this loop. So, what's the code for this loop? What do you need?" etc.
I'd really appriciate your help.
EDIT: Our teacher only let us use these libraries: iostream, fstream, cstdlib, cmath and cstring.
for all the elements in the vectors then make two loops, one for the i and one for the j. Just make sure every loop goes over all the legal values of i and j (and skip problematic ones like the last values).
You could alternatively try a recursion but I think two loops will do, and a 'for' loop might be the easiest.
Unfortunately, I think you've made a big mistake. From the problem description:
Check if within one of the two vectors (VY) there is a sequence of values in consecutive positions such that every element is included between two successive elements
Your code determines if there is a single element that fits the criteria. The problem is looking for a larger sequence.
You may want to check with the professor about this input:
vx = {1 2 19 21 3 4 9 10 5 6 }
vy = { 10 20}
With the current problem wording, I believe that this sequence works. I suspect that the professor intended to say that the two vectors are sorted, which makes the problem a whole lot easier to solve.
Also ask what if there are two sequences that meet the criteria?
It seems that the professor is on a "long journey"...
Anyway, let's just say that the two vectors must be sorted.
Your code determines if there is a single element that fits the criteria. The problem is looking for a larger sequence.
How do I check if every element fits the criteria? Should I do multiple condition variables? (okay, this sounds really bad)
no, you need not merge the whole length. merge as long as bigger elements found, taking elements alternately from vx and vy.
But your output and the example output (..., VX [i], VY [j], VX [i + 1], VY [j + 1], VX [i + 2], ...) are not the same. You print multiple vectors while in the example it prints one entire vector that fits the criteria.
The exercise is this:
Assigned two vectors (V1 and V2) of integers. Check if within one of the two vectors (VY) there is a sequence of values in consecutive positions such that every element is included between two successive elements of a sequence of elements of the other vector (VX):
VX [i] < VY [j] < VX [i + 1] and VX [i + 1] < VY [j + 1] < VX [i + 2]
Note that, the relationship in order to exist, the sequence of elements VY must have at least two elements and the sequence of elements VX must contain double elements of VY. If the check is positive, generate and print the vector obtained by melting the two successions respecting the found relation:
..., VX [i], VY [j], VX [i + 1], VY [j + 1], VX [i + 2], ...
I don't want you to write the code of this exercise. I just want to be "guided" through every point of the exercise, like:
"First do this loop. So, what's the code for this loop? What do you need?" etc.
I'd really appriciate your help.
EDIT: Our teacher only let us use these libraries: iostream, fstream, cstdlib, cmath and cstring.
apparently you also need #include <vector>
you wrote "V1" and "V2" only once. what's the relation vx and vy has with V1 and V2 ?
......
But your output and the example output (..., VX [i], VY [j], VX [i + 1], VY [j + 1], VX [i + 2], ...) are not the same. You print multiple vectors while in the example it prints one entire vector that fits the criteria.
Wait, every single piece of the example output is a number, right? I mean, for example:
VX [i] = number
VY [j] = another number
VX [i + 1] = another number
etc.
Am I right? Because if it isn't I think I didn't understand the exercise well.