在另一个数组中的一个数组中搜索元素 [英] searching elements in one array in another array

查看:103
本文介绍了在另一个数组中的一个数组中搜索元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况如下



I have a situation as below

string[] A = {'a','x','ab','z','c','d'}
string[] B = {'a','ab','c','xz','d'}





我需要写se用于搜索B中A中元素的arch方法。它应该用A中的元素搜索A中的每个元素,并且还应该用A中元素的组合搜索。

例如:B中存在'a' >
'xz'出现在B



我可以使用什么搜索过程来完成最小迭代。请建议。



谢谢



I need to write search method for searching elements in A in B. It should search every element in A with elements in B, and also with combination of elements in A.
Eg : 'a' present in B
'xz' present in B

What searching process i can use for this to finish in minimum iterations. Please suggest.

Thanks

推荐答案

首先,确定您要使用的语言:您已标记这可以找到你能找到的每种语言,每种语言的解决方案都不同。由于你的代码示例是C#,只需用它来标记。



其次,我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
Firstly, decide what language you want to use: you have tagged this with every language you could find, and the solutions will be different for each. Since your code sample is C#, just tag it with that.

Second, we do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


我创建了一个简单的例子,用于搜索另一个数组 -



使用System;

使用System.Linq;



名称空间ArrayComparison

{

class program

{

static void Main(string [] args)

{



string [] A = {a,x,ab,z,c,d};

string [] B = {a,ab,c,xz,d};



foreach(var x in A)

{

if(B.Contains(x))

{

Console.WriteLine(x);

}

}

Console.ReadLine();



}

}

}





但你提到
I create an simple example for search one array in another--

using System;
using System.Linq;

namespace ArrayComparison
{
class Program
{
static void Main(string[] args)
{

string[] A = { "a", "x", "ab", "z", "c", "d" };
string[] B = { "a", "ab", "c", "xz", "d" };

foreach (var x in A)
{
if(B.Contains(x))
{
Console.WriteLine(x);
}
}
Console.ReadLine();

}
}
}


But you mentioned that "
引用:

也包含A中元素的组合。

also with combination of elements in A.



所以你可以更详细地解释一下,这样我就可以相应地创建。

"
So could you please explain this in more detail so I could create accordingly.


这篇关于在另一个数组中的一个数组中搜索元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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