我正在尝试实现搜索算法来解决迷宫,但我在使用C ++创建图表时遇到了麻烦。它在Python中看起来像这样(使用字典):
GetStudentCollection().UpdateOne(s => s.Id == 12345, "{ $inc: { Grade: -1 } }");
键是一个TUPLE,值是TUPLES的列表。我环顾四周(有序地图等),但找不到以这种方式映射键值对的解决方案。 任何帮助将不胜感激......
答案 0 :(得分:1)
C ++让您比Python更多地考虑您要使用的数据。幸运的是,您的数据似乎非常明确。
您想要的词典可以实现为std::map
您想要的元组可以实现为std::pair
或std::tuple
。
// Assuming #include <tuple>
// Assuming #include <map>
// Assuming #include <vector>
using KeyType = std::tuple<int,int>;
using ValueType = std::vector<KeyType>;
std::map< KeyType, ValueType > Nodes;
Nodes[{6,6}]={{6,5},{6,7},{5,6},{7,6}};
Nodes[{1,3}]={{1,4},{2,3}};
这些using
行是为了便于阅读,可以根据需要进行更改或删除。