比如我要映射
1 2 3
3 4 1 -> 0
1 1 1
1 2 3
1 1 2 -> 1
1 1 1
等等。是否可以使用 std::map ?
编辑:我的意思是问我是否有一个二维数组或一维 vector 数组,如何将它与一些整数值映射。
最佳答案
使用 std::array
的 std::array
如下:
std::map< int, std::array<std::array< int , 3>, 3> > m =
{ {0, {{ { 1,2,3},
{ 3,4,1},
{ 1,1,1}
}}
},
{1, {{
{ 1,2,3},
{ 1,1,2},
{ 1,1,1}
}}
}
};
如果编译时行和列未知,您可以使用 std::vector
的 std::vector
std::map< int, std::vector<std::vector< int > > > m;
对于相反的矩阵到整数的映射,您只需颠倒顺序即可:
std::map< std::array<std::array< int , 3>, 3>, int > m_opp =
{ { {{ { 1,2,3},
{ 3,4,1},
{ 1,1,1}
}},
0
},
{ {{
{ 1,2,3},
{ 1,1,2},
{ 1,1,1}
}},
1
}
};
或
std::map< std::vector<std::vector< int > >, int > m_opp;
关于c++ - 如何将矩阵映射到某个整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743726/