creating vectors from vectors.

Sorry for the confusing title.

The question I am having is that say I have a vector that has 100 elements. (int from 0-100) and I want to create 10 new vectors that is going to contains number in range [0,10],[11,20] and so on.

1
2
3
4
vector<double> score;
for(int i=0;i<100;i++){
    	score.push_back(rand()%101);
    }


any help is welcome
You would have to... go through each element in the vector, check if it lies in that range, and put it in the right vector. You could accomplish this with either one statement like this:

1
2
3
4
for(auto element : score)
{
    //...
}


with some if statements inside to check the value of element, or using multiple for statements like that, but one per vector.
so I will end up initializing 10 vectors and then populating them one by one.

okay, once i do that I want to find the vector with the largest amount of points.

I am thinking making a vector and then pushing back all the new vectors size() one by one then sorting it so the last element will be my largest element.

is there any easier way?
Well, at that point you know how many vectors there are- 0-10, 11-20, 21-30, 31-40, 41-50, 51-60, 61-70, 71-80, 81-90, 91-100. Why not just use an array?
would you be able to give me an example.

I am confused on how an array would be better than a vector.
Well, for finding the vector with the largest size, you know there are 10 vectors. Hence, an array of size 10 would work perfectly well- the number of vectors would never change, so why make it ore difficult with another vector?
Topic archived. No new replies allowed.