多个向量共有的元素...... [英] elements common to more than one vector...

查看:86
本文介绍了多个向量共有的元素......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个我可以使用的功能,给定一些向量元素

对所有人来说是通用的?


例如

vector< int> a;

vector< int> b;


a.push_back(1);

a.push_back(2);

a.push_back(3) ;

a.push_back(4);


b.push_back(2);

b.push_back(4);


有什么能让我回答2和4的答案? (结果将

存储在另一个向量中)。


如果我有两个以上的向量进行比较怎么办 - 我会以某种方式称之为

对每一对的功能? (即a与b,b与c,a与c?)

Is there a function that I can use that given a few vectors which elements
are common to all?

for example
vector<int> a;
vector<int> b;

a.push_back( 1 );
a.push_back( 2 );
a.push_back( 3 );
a.push_back( 4 );

b.push_back( 2 );
b.push_back( 4 );

Something that will give me back the answer of 2 and 4? (The results would
be stored in another vector).

What if I have more than 2 vectors to compare - would I somehow call this
function against each pair? (ie a vs. b, b vs. c, a vs. c?)

推荐答案



Winbatch写道:

Winbatch wrote:
是否有一个我可以使用的函数,给定一些向量的元素
对所有人来说是通用的?

例如
vector< int> a;
向量< int> b;

a.push_back(1);
a.push_back(2);
a.push_back(3);
a.push_back(4);

b.push_back(2);
b.push_back(4);

有什么能让我回答2和4的答案? (结果将存储在另一个向量中。)

如果我有两个以上的向量进行比较怎么办?我会以某种方式对每一对称为
函数吗? (即a vs. b,b vs. c,a vs. c?)
Is there a function that I can use that given a few vectors which elements
are common to all?

for example
vector<int> a;
vector<int> b;

a.push_back( 1 );
a.push_back( 2 );
a.push_back( 3 );
a.push_back( 4 );

b.push_back( 2 );
b.push_back( 4 );

Something that will give me back the answer of 2 and 4? (The results would
be stored in another vector).

What if I have more than 2 vectors to compare - would I somehow call this
function against each pair? (ie a vs. b, b vs. c, a vs. c?)




也许你真的想玩std :: set?



Maybe you really want to be playing with std::set?


>
也许你真的想玩std :: set?
Maybe you really want to be playing with std::set?



即使我确实切换到设置,我的问题仍然存在,对吧?



Even if I did switch to set, my question still stands, right?




" Winbatch" <无线****** @ techie.com>在消息中写道

新闻:3%**************** @ news-wrt-01.rdc-nyc.rr.com ...

"Winbatch" <wi******@techie.com> wrote in message
news:3%****************@news-wrt-01.rdc-nyc.rr.com...

也许你真的想玩std :: set?

Maybe you really want to be playing with std::set?



即使我确实切换到设置,我的问题仍然存在,对吗?



Even if I did switch to set, my question still stands, right?




它是否带有set_intersection?如果我有超过2套怎么办?我想我

只是对每一组进行函数调用?



Is it with set_intersection? What if I have more than 2 sets? I guess I
just do the function call for each set against the last?


这篇关于多个向量共有的元素......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆