两个字符串,怎样通过查找,验证其中一个是否是另一个的子字符串呢?
用字符数组还是字符串来实现呢
我写的程序,可是有错误,不知道错在哪里
class Program
{
public void merge(ref int[] a ,ref int[] b)
{
int[] c = new int[20];
int i = 0; int j = 0;int p=0;
while(i<10&&j<10&&p<20)
{
if (a[i] == b[j])
{
c[i] = a[i];
i++; p++;
}
else
{
if (a[i] > b[j])
{
c[p] = b[j]; p++; j++;
}
else
{
c[p] = a[i]; i++; p++;
}
}
}
for (p = 0; p <20; p++)
Console.Write(c[p]+" ");
}
static void Main(string[] args)
{
int[] a = new int[10] { 1,3,5,7,9,11,13,15,17,19};
int[] b = new int[10] {2,4,6,8,10,12,14,16,18,20};
Program p = new Program();
p.merge(ref a, ref b);
Console.ReadLine();
}
}