如何检查给定的向量是否包含在我的向量中? [英] How to check whether the given vector is contained in my vector or not?
问题描述
Stl函数,通知另一个向量中的向量是否包含任何顺序..
我的意思是
A {1,2,3,4,5 ,5,6,1}
B {2,1,6} C {5,5,1}
当你比较A和B时它应该返回真正的bcs它以任何顺序包含在其中。对于C它也应该是正确的,因为C被包含在A中(以任何顺序)。
一种解决方案:排序他们和检查通过包括()..
除此之外的其他....
我尝试了什么:
我尝试了其中一种方式即排序然后使用includes()...执行以下操作...我的意思是它可能在任何其他方式?
Stl function that notifies if a vector is contained in another vector but in any order ..
I mean
A{ 1,2,3,4,5,5,6,1}
B{2,1,6} C{5,5,1}
When you compare A and B it should return true bcs it is contained in it in any order..for C it should also be correct because C is conatined in A.(in any order).
One solution : sort them and check via includes( ) ..
Any other than this....
What I have tried:
I have tried one of the way i.e sort and then using includes() ... do the following thing...i mean is it possible in any other way?
推荐答案
我的意思是它可以在任何其他方式?
i mean is it possible in any other way?
当然有可能:迭代候选向量(例如 B
)项目,检查项目是否包含在中A
。但是你必须使已经匹配的 A
项无效(你可以使用另一个向量)。
Of course it is possible: iterating over the candidate vector (e.g. B
) items, check if the item is contained in A
. However you have to invalidate the items of A
already matched (you could use another vector for the purpose).
这篇关于如何检查给定的向量是否包含在我的向量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!