maybe simple for you but not for me MULTIARRAY

i have multiarray like this
1
2
3
4
5
6
 
1       2       3
4       5       6
7       8       9
10      11      12
13      14      15

so i want make new array and the new array should be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
1       2       3
1       5       6
1       8       9
1       11      12
1       14      15
4       2       3
4       5       6
4       8       9
4       11      12
4       14      15
7       2       3
7       5       6
7       8       9
7       11      12
7       14      15
10      2       3
10      5       6
10      8       9
10      11      12
10      14      15
13      2       3
13      5       6
13      8       9
13      11      12
13      14      15
 

how can i do that ? any idea please ??
I'm afraid this is the best I've been able to work out:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>

void waitForEnter();

int main()
{
    std::vector<std::array<int, 3>> myseq(5);
    {
        int incr {1};
        for(auto& a : myseq) {
            for(auto& b : a) { b = incr++; }
        }
    }
    for(const auto& a : myseq) {
        for(const auto& b : a) { std::cout << std::setw(5) << b << ' '; }
        std::cout << '\n';
    }
    for(auto& a : myseq) { a.at(0) = 1; }
    std::vector<std::array<int, 3>> templ(myseq); // template to replicate
    for(int i{}, incr = 4; i<4; ++i) {
        std::vector<std::array<int, 3>> tmp(templ);
        for(auto& a : tmp) { a.at(0) = incr; }
        myseq.insert(myseq.end(), tmp.begin(), tmp.end());
        incr += 3;
    }
    std::cout << "\n\n";
    for(const auto& a : myseq) {
        for(const auto& b : a) { std::cout << std::setw(5) << b << ' '; }
        std::cout << '\n';
    }
    waitForEnter();
    return 0;   
}

void waitForEnter()
{
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}


Hope someone is going to add a more elegant solution.
@Enoizat
Don't do the homework of someone else.
@coder777, thank you for your advice.
In this case, I don't think it was a homework.

@Enoizat Thank you very much for your help, not only in this question but also my last question hope i can talk in person so that you know i'm in such trouble right now and i really2 need a help.
so this people like @coder777 not only judge my question saying it a homework or anything,
and please if someone help other people is not your business, mind your own business why are you so jealous. are u ok?
split it into first column (f) and other columns (oc), then flat iteration to generate should work.

for fr = all the rows in f
for ocr = all the rows in oc
insert {f[fr]}{oc[ocr]}

if you used valarray instead of vector, you could slice this and be done with a simple bit of code.

it really does look like a typical homework problem, which we prefer not to do because it is dishonest to do that for someone (you are assisting them to cheat). It can be a grey area... a few HW problems may be also a real world problem, or a self-learning exercise etc... we do get a lot of people trying to cheat here, so look at it from that perspective.
Last edited on
@jonnin yeah you were right i dont look it from that prespective, my bad change the number into easy one it seem i should write down my real number so this people can understand its not just a typical homework.
i think i will need your help later, thank u
Topic archived. No new replies allowed.