Relevant but a different problem than this: https://stackoverflow.com/a/58474681/12174978
in this question, I have learned that how I can find the first and second repetitive elements of a variable using a map. I'm thinking to work with a for loop that will generate repetitive numbers using a defined function.
#include <iostream>
using namespace std;
int addition(int a, int b)
{
int r;
if (b < 6)
{
r = a;
}
else {
r = a + b;
}
return r;
}
int main()
{
int z;
int a = 1;
for (int b = 0; b < 15; b++)
{
z = addition(a, b);
cout << "The result is " << z << "\n" << endl;
}
}
From the above code what I have got is some repetitive 1 and other numbers as well (1,1,1,1,... 9,10, 11...16). So I would like to get only the first two same numbers position and printout.
If I change the above code we might get the output element different where the repetition would be different too. But I always want to consider the only first two repetitive of the same number.
For example, if the repetition in the print out like this: 6,3,4,5,5,5,5,6,7,6,
I want to consider only the first two 6 positions which are in [0], [7] place, and for 5, the first two are in [3], and [4] place.
I tried to do this in the way I mentioned in the link, but what I have ended up is I was getting the same position multiple times.
UPDATE: The reason I would like to get the repetition of the first time and second time of a number because I would like to selectively use that number and position as well in my analysis.
So my expected output would be only the elements that are more than once. I would like to get their position as well, so I can know which one came in the for loop and which one second